首页 新闻 会员 周边

EF实体映射到存储过程

0
悬赏园豆:10 [已解决问题] 解决于 2014-06-17 19:27

存储过程返回的是实际表的数据,在实体里的定义是这样的:

public enum ProductType
{
    Type1,
    Type2
}

public class Product
{
    public int ProductTypeId{get;set;}
    public ProductType ProductType
    {
        get
        {
            return (ProductType)ProductTypeId;
        }
        set
        {
            ProductTypeId = (int)value;
        }
    }
}

    public partial class ProductMap : EntityTypeConfiguration<Product>
    {
        public ProductMap()
        {
            this.ToTable("Product");
            this.HasKey(p => p.Id);
            this.Property(p => p.Name).IsRequired().HasMaxLength(400);
            this.Property(p => p.MetaKeywords).HasMaxLength(400);
            this.Property(p => p.MetaTitle).HasMaxLength(400);
            this.Ignore(p => p.ZupoProductType);
            this.Property(p => p.ZupoProductTypeId)
                    .HasColumnName("ProductType");

            this.HasMany(p => p.ProductTags)
                .WithMany(pt => pt.Products)
                .Map(m => m.ToTable("Product_ProductTag_Mapping"));
        }
    }


在使用Translate的时候,报告ProductTypeId未找到列。

519740105的主页 519740105 | 大侠五级 | 园豆:5810
提问于:2014-05-19 15:14
< >
分享
最佳答案
0

不支持这样的枚举转换吧,EF5可以直接将字段定义成枚举.你的版本是

收获园豆:10
平常心队长 | 小虾三级 |园豆:1113 | 2014-05-19 15:29

跟枚举没关系。只是一个整型字段ProductType映射到属性ProductTypeId,因为ProductTypeId是非空的,而select的结果里只有ProductType而没有ProductTypeId。

 

我知道,只要在存储过程里把select语句的ProductType AS为ProductTypeId就可以了,但~~~很麻烦。

519740105 | 园豆:5810 (大侠五级) | 2014-05-19 15:31
其他回答(1)
0

佳付通专业卡类消耗通道,API接口对接,回收各类充值卡,通讯卡,游戏卡,人工寄售,接口对接
高比例,抗投诉,秒结算,长期稳定!
QQ:1090603892
网址:www.lcardy.com 联系电话:0898-65637899

佳付通 | 园豆:210 (菜鸟二级) | 2014-05-19 15:35
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册