1 entity-framework ef-code-first
我有以下型号,但我一直收到错误:
未处理的异常:System.InvalidOperationException:发生关系乘法约束违规:EntityReference只能有一个关联对象,但查询返回了多个相关对象.这是一个无法恢复的错误.
public class Tournament
{
public long TournamentId { get; set; }
public string Title { get; set; }
public virtual User CreatedBy { get; set; }
}
public class User
{
public int UserId { get; set; }
}
modelBuilder.Entity<Tournament>()
.HasRequired(t => t.CreatedBy)
.WithOptional()
.Map(c => c.MapKey("CreatedById")); // correct column name
Run Code Online (Sandbox Code Playgroud)
您的模型流畅配置条目不正确.更改如下
modelBuilder.Entity<Tournament>()
.HasRequired(t => t.CreatedBy)
.WithMany()
.Map(c => c.MapKey("CreatedById")); // correct column name
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3470 次 |
| 最近记录: |