簡體   English   中英

子類上的 Insight.Database [BindChildren] 不起作用

[英]Insight.Database [BindChildren] on subclass not working

我在我的 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM