【问题标题】:entity framework database first scaffolded dbcontext do not enable entity navigation实体框架数据库首先搭建的 dbcontext 不启用实体导航
【发布时间】:2015-09-09 22:05:07
【问题描述】:

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

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:

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; }
    }

【问题讨论】:

    标签: asp.net-core eager-loading ef-database-first entity-framework-core


    【解决方案1】:

    嗯,一个很明显的答案。缺少使用。

    using Microsoft.Data.Entity;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多