我似乎无法解决我的映射问题;关系是一个用户可能有很多场地,场地必须有一个用户.
我的场地类看起来像:
public class Venue : BaSEObject,IBaSEObject { [required] public virtual User Owner { get; set; } [required] [MaxLength(50)] public string Name { get; set; } }
我的用户类看起来像:
public class User : BaSEObject,IBaSEObject { [required] public string Name { get; set; } [required] [DisplayName("Email")] public string EmailAddress { get; set; } [required] public string Password { get; set; } public bool Active { get; set; } public virtual ICollection<Venue> Venues { get; set; } }
DbContextClass按要求
public class SystemContext : DbContext,IDbContext { public SystemContext() : base("SystemContext") { Database.SetInitializer<SystemContext>(null); Configuration.ProxyCreationEnabled = false; Configuration.LazyLoadingEnabled = true; } public SystemContext(string connectionstringname = "SystemContext") : base(connectionstringname) { Database.SetInitializer<SystemContext>(null); Configuration.ProxyCreationEnabled = false; } public new IDbSet<T> Set<T>() where T : class { return base.Set<T>(); } protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity<User>().HasMany(x=>x.Venues); } public DbSet<PublicQueries> PublicQueries { get; set; } public DbSet<Venue> Venues { get; set; } public DbSet<User> Users { get; set; } }
当我从数据库加载User类时,Venues似乎总是为空?
我以前做过类似的事,但不记得我是如何重新安排的.
谢谢