gpt4 book ai didi

servicestack - OrmLite 按多列连接表

转载 作者:行者123 更新时间:2023-12-04 10:28:15 27 4
gpt4 key购买 nike

使用 OrmLite 如何按多列连接表?

我有 Notes可以包含 QutoeHeader 数据的表或 OrderHeader所以我尝试加入并使用 SelectMulti()像这样:

var userSpecificQuery =
_db
.From<Customer>()
.Where(x => x.SalesRepresentativeId == userId)
.LeftJoin<Customer, QuoteHeader>((c, q) => c.Id == q.CustomerId)
.LeftJoin<Customer, OrderHeader>((c, o) => c.Id == o.CustomerId)
.LeftJoin<OrderHeader, QuoteHeader, Notes>((oh,qh, n) => oh.Id == n.OrderId || qh.Id == n.QuoteId)
;


var userSpecificRecords =
_db.SelectMulti<Customer, QuoteHeader, OrderHeader, Notes>(userSpecificQuery);

但我得到错误:

table name "quote_header" specified more than once



我想加入所有与 OrderId 或 QuoteId 匹配的记录。我尝试了几种不同的方法并得到相同的错误。这可能吗?

编辑:

这是笔记模型
public class Notes : BaseModel
{
[AutoIncrement]
public long Id { get; set; }
[ForeignKey(typeof(QuoteHeader))]
public long? QuoteId { get; set; }
[ForeignKey(typeof(OrderHeader))]
public long? OrderId { get; set; }
public string NoteText { get; set; }
}

最佳答案

而不是加入 QuoteHeader多次,将条件移动到 Where :

db.From<Customer>()
.Where(x => x.SalesRepresentativeId == userId)
.LeftJoin<Customer, QuoteHeader>((c, q) => c.Id == q.CustomerId)
.LeftJoin<Customer, OrderHeader>((c, o) => c.Id == o.CustomerId)
.LeftJoin<OrderHeader, Notes>((oh, n) => oh.Id == n.OrderId)
.Where<OrderHeader,QuoteHeader,Notes>((oh,qh,n) => oh.OrderId != null || qh.Id == n.QuoteId)

关于servicestack - OrmLite 按多列连接表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60537883/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com