首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >实体框架数据库首先是脚手架dbcontext不启用实体导航

实体框架数据库首先是脚手架dbcontext不启用实体导航
EN

Stack Overflow用户
提问于 2015-09-09 13:22:01
回答 1查看 434关注 0票数 0

示例: dbContext.Shortlist.Include(a => a.Shortlist_crew)。.Include()部分根本不可用。在任何其他实体上相同: table.Include(q=>q.OtherEntity)。这是来自运行dbcontext脚手架EntityFramework.SqlServer的生成类。在asp.net 5 (beta 7)项目中运行EF 7 beta-7,这里缺少什么?生成的db上下文的片段:

代码语言:javascript
复制
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
...
modelBuilder.Entity<Shortlist>(entity =>
            {
                entity.ToTable("Shortlist", "dbSchemaName");
                entity.Property(e => e.id).ValueGeneratedNever();
                entity.Property(e => e.name).Required();
                entity.Property(e => e.production_id).Required();
                entity.Property(e => e.user_id).Required();
                entity.Reference(d => d.production).InverseCollection(p => p.Shortlist).ForeignKey(d => d.production_id);
                entity.Reference(d => d.user).InverseCollection(p => p.Shortlist).ForeignKey(d => d.user_id);
            });

modelBuilder.Entity<Shortlist_crew>(entity =>
            {
                entity.ToTable("Shortlist_crew", "dbSchemaName");
                entity.Property(e => e.id).ValueGeneratedNever();
                entity.Property(e => e.added)
                    .Required()
                    .HasDefaultValueSql("getutcdate()");
                entity.Property(e => e.crew_id).Required();
                entity.Property(e => e.shortlist_id).Required();
                entity.Reference(d => d.shortlist).InverseCollection(p => p.Shortlist_crew).ForeignKey(d => d.shortlist_id);
                entity.Reference(d => d.crew).InverseCollection(p => p.Shortlist_crew).ForeignKey(d => d.crew_id);
            });
...
}
public virtual DbSet<Shortlist> Shortlist { get; set; }
public virtual DbSet<Shortlist_crew> Shortlist_crew { get; set; }

而生成的POCO:

代码语言:javascript
复制
public class Shortlist
    {
        public Shortlist()
        {
            Production_shortlist = new HashSet<Production_shortlist>();
            Shortlist_crew = new HashSet<Shortlist_crew>();
        }

        public Guid id { get; set; }
        public string name { get; set; }
        public Guid production_id { get; set; }
        public string remarks { get; set; }
        public Guid user_id { get; set; }
        public virtual ICollection<Production_shortlist> Production_shortlist { get; set; }
        public virtual ICollection<Shortlist_crew> Shortlist_crew { get; set; }
        public virtual Production production { get; set; }
        public virtual SearchUser user { get; set; }
    }

public class Shortlist_crew
    {
        public Guid id { get; set; }
        public DateTimeOffset added { get; set; }
        public Guid crew_id { get; set; }
        public Guid shortlist_id { get; set; }
        public virtual Crew crew { get; set; }
        public virtual Shortlist shortlist { get; set; }
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-09 14:05:07

答案很明显。错过了一次使用。

代码语言:javascript
复制
using Microsoft.Data.Entity;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32480755

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档