我正在努力使用Dapper / FastCrud将多个列映射到同一张表。
我具有这种结构(试图排除我认为不相关的所有内容)
public class Process
{
public int Id {get; set;}
public bool IsTemplate { get; set; }
[ForeignKey("CreatedByUser")]
public int CreatedByUserId {get; set;}
[ForeignKey("UpdatedByUser")]
public int? UpdatedByUserId { get;set; }
public User CreatedByUser { get; set; }
public User UpdatedByUser {get;set; }
}
public class User
{
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Process> CreatedProcesses { get; set; }
public virtual ICollection<Process> UpdatedProcesses { get; set; }
public User
{
CreatedProcesses = new HashSet<Process>();
UpdatedProcesses = new HashSet<Process>();
}
}
当我尝试通过此方法获取流程
var processes = connection.Find(statement => statement
.Where($"{nameof(Process.IsTemplate):C} = 1")
);
我收到此错误:
InvalidOperationException: Multiple entity referencing properties were registered for the 'Models.Process' - 'Models.User' relationship
Dapper.FastCrud.Mappings.EntityMapping.<ConstructChildParentEntityRelationships>b__37_3(IGrouping<Type, PropertyMapping> groupedRelMappings)
此参考资料表明Dapper可以做到这一点,但我不知道如何让FastCrud处理 Dapper multi mapping two properties of the same type
fastcrud的这个线程也可以处理该问题 https://github.com/MoonStorm/Dapper.FastCRUD/issues/65
我尝试将[NotMapped]放在User的ICollection上,但没有成功,仍然是同样的错误。