FetchOneToMany没有任何成功,下面的示例不会返回很多值。我是从PetaPoco迁移的,当时我不得不编写相关器来映射一对多,感觉好像我在这里遗漏了一些明显的东西。...
通话:
Database.FetchOneToMany<GroupDto>(x => x.Users, sqlQueries.UserGroupWithUsers, value).FirstOrDefault();
GroupDto如下所示:
[TableName("Groups")]
[ExplicitColumns]
[PrimaryKey("GroupId", AutoIncrement = true)]
public class UserGroupPoco
{
[Column("GroupId")]
[PrimaryKeyColumn(AutoIncrement = true)]
public int GroupId { get; set; }
// plus many more columns
[ResultColumn]
public List<UserDto> Users { get; set; }
}
和UserDto:
[TableName("Users")]
[ExplicitColumns]
[PrimaryKey("Id", AutoIncrement = true)]
public class UserDto
{
[Column("Id")]
[PrimaryKeyColumn(AutoIncrement = true)]
public int Id { get; set; }
[Column("UserId")]
public int UserId { get; set; }
[Column("GroupId")]
public int GroupId { get; set; }
}
和SQL:
"SELECT g.*, u.* FROM Groups g
LEFT JOIN Users u
on g.GroupId = u.GroupId
AND g.GroupId = @0";
返回无任何错误,返回有效的Group对象,但是Users为null。在SSMS中运行SQL将返回预期结果。
我要去哪里错了,如何改善DTO结构?