首页 新闻 会员 周边

EF code first 不能自动生成外键实体

0
悬赏园豆:50 [已解决问题] 解决于 2012-05-28 16:29
    public class Product : EntityBase<int>, IAggregateRoot, IProductAttribute
    {
        public string Name { get; set; }
        public decimal Price { get; set; }
        public int SalesAmount { get; set; }
        public string Introduction { get; set; }
        public Brand Brand { get; set; }
        public Category Category { get; set; }

        protected override void Validate()
        {
            throw new NotImplementedException();
        }

        public override string ToString()
        {
            return this.Name;
        }
    }
查询生成Product实体时 属性Category是为null的,在数据库中Category和Product是一对多关系,请问怎么样才能自动生成Category。
Ps:数据库是我自己手动创建的,然后用code first匹配的
 
浩GE的主页 浩GE | 初学一级 | 园豆:105
提问于:2012-05-27 23:32
< >
分享
最佳答案
2
public virtual Category Category{set;get;}
public virtual int? CategoryId{set;get;}
收获园豆:30
sinhbv | 老鸟四级 |园豆:2579 | 2012-05-28 09:07
其他回答(1)
0

查询时需要.Include(p=>p.Category)

收获园豆:20
dudu | 园豆:30994 (高人七级) | 2012-05-28 13:30
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册