问题描述
[table("state")]
public class StateCodeDTO {
[Key]
[column("state_code")
string StateCode { get; set; }
[column("state_name")]
string StateName { get; set; }
}
[table("location")]
public class LocationDTO {
[Key]
[column("id")
int Id { get; set; }
[column("location_name")]
string Location_Name { get; set; }
}
我可能创建了一个查询,其中错误地包含了两个实体。我不记得我做了什么,但这是一个错误。现在我卡住了
Entity Framework
认为这两个表之间存在关系。我的上下文我有以下 DbSet:
public DbSet<LocationDTO> Location@R_679_4045@ion { get; set; }
public DbSet<StateCodeDTO> StateCode { get; set; }
如果我发出以下调用:
var stateDTOs = _dbContext.StateCode.ToList();
我有可怕的 Invalid column name
例外
sqlException: 无效的列名“LocationDTId”。
Microsoft.Data.sqlClient.sqlConnection.OnError(sqlException 异常, bool breakConnection,Action wrapCloseInAction) Microsoft.Data.sqlClient.sqlInternalConnection.OnError(sqlException 异常,布尔 breakConnection,动作 wrapCloseInAction) Microsoft.Data.sqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj、bool callerHasConnectionLock、bool asyncclose) Microsoft.Data.sqlClient.TdsParser.TryRun(RunBehavior runBehavior,sqlCommand cmdHandler、sqlDataReader 数据流、 BulkcopySimpleResultSet bulkcopyHandler、TdsParserStateObject stateObj,out bool dataReady)
请注意,一切正常,直到我发出无效查询,这似乎使所有内容陷入困境。我认为这与我所做的无关,我只需要一种方法来告诉 Entity Framework
这两个实体不相关。似乎它正在将 Code First
约定 ClassNameKey 应用于位置表,并认为 LocationDTOId
是状态表中的外键。这与事实大相径庭。
How can I tell Entity Framework that these entities are unrelated?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)