Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 实体框架5.0-为多对多关系编写查询_C#_.net_Entity Framework 5_One To Many - Fatal编程技术网

C# 实体框架5.0-为多对多关系编写查询

C# 实体框架5.0-为多对多关系编写查询,c#,.net,entity-framework-5,one-to-many,C#,.net,Entity Framework 5,One To Many,我目前为我的实体框架设置了以下模型和DB上下文。 关系如下:表a和表B都有多对多关系 DBContext: public partial class MyContext : DbContext { public MyContext (string connString) : base(connString) { this.Configuration.ProxyCreationEnabled = false;

我目前为我的实体框架设置了以下模型和DB上下文。 关系如下:表a和表B都有多对多关系

DBContext:

 public partial class MyContext : DbContext
    {
        public MyContext (string connString)
            : base(connString)
        {
            this.Configuration.ProxyCreationEnabled = false;
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {

            base.OnModelCreating(modelBuilder);

            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

               modelBuilder.Entity<TableA>().HasMany(x => x.TableB).WithMany(
                x => x.TableA).Map(m =>
                {
                    m.ToTable("TableC");
                    m.MapRightKey("B_ID");
                    m.MapLeftKey("C_ID");
                });            

        }

        public DbSet<TableA> TableA { get; set; }
        public DbSet<TableB> TableB { get; set; }


    }
它根据需要返回表A对象列表,但是对于列表中的每个对象,它不包括实体定义中指示的表B属性列表

当我这样做时,同样的行为也会发生

MyContext.TableB.GetList();

我的设置是否正确,或者我是否缺少一些微妙的设置

延迟加载可能已禁用,因为您已将ProxyCreationEnabled设置为false。您可能需要删除该行,或者立即加载相关信息。

这只是猜测,但延迟加载可能已禁用,因为您已将ProxyCreationEnabled设置为false。您需要删除该行或加载相关信息。这似乎解决了我的问题。如果您愿意,请继续并将此作为答案提交。谢谢莫顿·默特纳。谢谢,很高兴能帮上忙。
MyContext.TableA.GetList();
MyContext.TableB.GetList();