EF6多对多关系:SqlException:无效的列名称'SubAccount_SubAccountID'

问题描述

使用以下方法从Entity Framework EF6加载数据时出现错误:

SqlException:无效的列名称'SubAccount_SubAccountID'。

这是我对EF6的查询

var subAccounts = Context
            .SubAccount
            .Include(i => i.Users)
            .ToList();

Exception Image

此ICollat​​ion用户使用Fluent API是多对多关系。

这是UserConfiguration类中的Fluent API配置:

HasMany(p => p.SubAccounts)
            .WithMany(r => r.Users)
            .Map(mc =>
            {
                mc.MapLeftKey("UserID");
                mc.MapLeftKey("SubAccountID");
                mc.ToTable("MOB_USER_SUBACCOUNT");
            });

有人可以帮我吗?

解决方法

尝试此指南:

https://www.entityframeworktutorial.net/code-first/configure-many-to-many-relationship-in-code-first.aspx

它将使用EF6 Code First和Fluent Api指导您进行多对多关系的配置

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...