Insight.Database [BindChildren] 在子类上不起作用
Insight.Database [BindChildren] on subclass not working
我在我的 C# 项目中使用 insight.database
。我有一个 class 有一个 subclass。我在我的 SP 中使用内部连接来展平并获取我的字段。但是,我希望某些查询结果字段映射到我的 subclass。它没有像我预期的那样工作。我曾尝试分别在 parent 和 subclass 上使用 BindChildren 属性,然后同时使用,但其中 none 有效。父 class 映射正确,但没有值分配给子 class 属性。有人可以让我知道我做错了什么吗?
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);
}
父级 class:
public class User
{
public int Id{get;set;}
public string FirstName{get;set;}
public string LastName{get; set;}
public UserGroup Group{get;set;}
}
子 class :
[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
我在我的 C# 项目中使用 insight.database
。我有一个 class 有一个 subclass。我在我的 SP 中使用内部连接来展平并获取我的字段。但是,我希望某些查询结果字段映射到我的 subclass。它没有像我预期的那样工作。我曾尝试分别在 parent 和 subclass 上使用 BindChildren 属性,然后同时使用,但其中 none 有效。父 class 映射正确,但没有值分配给子 class 属性。有人可以让我知道我做错了什么吗?
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);
}
父级 class:
public class User
{
public int Id{get;set;}
public string FirstName{get;set;}
public string LastName{get; set;}
public UserGroup Group{get;set;}
}
子 class :
[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