使用.Select().IntoTable()批量插入时,为什么在生成的SQL文中会多出两个字段。 返回
SqlSugar
沟通中
5
151
tiantian 发布于2周前
悬赏:0 飞吻
使用以下的批量插入时,SQL文的select中会自动多出两个字段,("[it1].[ID] AS SugarNav_ID" 与 "[it1].[CustomerID] AS SugarNav_CustomerID ")
return db.Queryable<InvoiceDetailModel>()
.Includes(it1 => it1.Customer)
.LeftJoin<InvoiceNoticeModel>((it1, it2) => it1.InvoiceCD == it2.InvoiceCD && it1.InvoiceDate == it2.InvoiceDate)
.Where((it1, it2) => it1.SalesDate == salesDate && servList.Contains(it1.ServiceID))
.Select((it1, it2) => new InvoiceDetailIFModel
{
ID = it1.ID,
CustomerID = it1.CustomerID,
InvoiceCD = it1.InvoiceCD,
CustomerName = it1.Customer!.CustomerName,
SlipDate = DateTime.Parse($"{it1.SalesDate}/01"),
InvoiceYM = it1.InvoiceDate,
ServiceID = it1.ServiceID,
SectionCD = it1.SectionCD,
BulkNo = it1.BulkNo,
Notice = it2.Notice,
Notice2 = it2.Notice2,
ApprovalNo = it1.ApprovalNo,
PreID = it1.PreID,
ItemCD = it1.ItemCD,
ItemName = it1.ItemName,
Qty = it1.Qty,
UnitCost = it1.UnitCost,
TaxCode = "2",
TaxRate = (GlobalData.TaxRate * 100).ObjToInt(),
Note = it1.Note,
ElementCD = it1.ElementCD,
Sort = it1.Sort,
UpdateTime = it1.UpdateTime,
IsDeleted = it1.IsDeleted
})
.IntoTable<InvoiceDetailIFModel>();
热忱回答(5)
-
fate sta VIP0
2周前.Includes(it1 => it1.Customer)删掉就行。intotable用不到Includes
0 回复 -
tiantian VIP0
1周前CustomerName = it1.Customer!.CustomerName,
在Select中用到Includes了。删了没法取得CustomerName。
0 回复 -
fate sta VIP0
1周前it1.Customer!.CustomerName 不需要incudes
0 回复 -
fate sta VIP0
1周前换成
.IncludeFeftJoin也行 (it1 => it1.Customer)0 回复 -
tiantian VIP0
1周前非常感谢!
用
.IncludeLeftJoin替换.Includes就解决了,不会自动生成多余字段了。
0 回复