从数据库中检索时,数值将转换回枚举表示形式

时间:2019-07-10 07:32:32

标签: code-first asp.net-core-2.2

公共IQueryable ListPousadas()         {

        var y = _db.Set<Pousada>().AsNoTracking().Where(x => x.Deleted == false);
        return y;
    }

   public enum PousadaSize
    {
        Small = 1, Medium = 2, Large = 4, ExtraLarge = 8
    }

在邮递员中: [     {         “ id”:“ 3f5b8ad1-feb4-42f8-8095-ca5011823011”,         “名称”:“ USATest”,         “所有者”:“ USATest1”,         “ state”:“ Kol”,         “ city”:“ Asansol”,         “大小”:1,//这里我要显示小         “ language”:“ en”,         “ legalRepresentative”:“ TestOwner”,         “ hostingFacilityType”:2         “ createdAt”:“ 2019-07-10T06:19:49.752”,         “ updatedAt”:null,         “ deletedAt”:null,         “已删除”:false,         “ isActive”:是     } ]

我正在尝试以下代码:

        builder
            .Entity<Pousada>()
            .Property(u => u.PousadaSize)
            .HasConversion(
            v => v.ToString(),
            v => (PousadaSizeEnum.PousadaSize)Enum.Parse(typeof(PousadaSizeEnum.PousadaSize), v));

0 个答案:

没有答案