c# - 子类上的 Insight.Database [BindChildren] 不起作用
问题描述
我正在使用insight.database
我的 c# 项目。我有一个有子类的类。我在我的 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
推荐阅读
- python - 如何为不同列中的条件过滤 DataFrame 的特定列
- python - 使用 python flask 编写一个连接和读取 azure web 应用程序上安装的存储的代码?
- oauth-2.0 - OAuth2 over HTTPS 启用负载均衡器
- r - 嵌套 for 循环中的打印输出和存储向量的结果不同。是什么赋予了?
- javascript - 捕获交易拒绝-moralis
- python - 使用 Cython 保护 Windows 中的 Python 代码
- python - 算法的 numpy 向量化以返回二进制序列中连续部分的索引
- java - 在底部导航视图上多次点击时应用程序崩溃
- java - Allure testNg:向环境部分添加细节
- lme4 - gtsummary 和 lmerTest