我在我的C#项目中使用insight.database
。我有一个带有子类的类。我在SP中使用内部联接来展平并获取我的字段。但是,我希望某些查询结果字段映射到我的子类。它没有按我预期的那样工作。我尝试过分别在父类和子类上使用BindChildren属性,然后同时使用,但是这些都不起作用。父类可以正确映射,但是没有将值分配给子类属性。有人可以让我知道我在做什么错吗?
SQL(spGetUserById):
select t1.id, t1.FirstName, t1.LastName,t2.Id, t2.GroupName
from table1 t1
inner join table2 t2 on t1.groupId = t2.id
where t1.id = @userId
存储库界面:
public interface IUserRepository
{
[Sql("spGetUserById")]
User GetUserById(int userid);
}
家长班:
public class User
{
public int Id{get;set;}
public string FirstName{get;set;}
public string LastName{get; set;}
public UserGroup Group{get;set;}
}
子类:
[BindChildren]
public class UserGroup
{
public int Id{get;set;}
public string GroupName{get;set;}
}
因为这是一个OneToOne映射,而不是父->子列表映射,所以我可以使用Recordset代替[BindChildren]:
public interface IUserRepository
{
[Recordset(0, typeof(User), typeof(UserGroup))]
[Sql("spGetUserById")]
User GetUserById(int userid);
}
解决方案发布在这里:https://github.com/jonwagner/Insight.Database/issues/437