戈壁老王 - 2025年9月
type: channel
link: https://www.wangyiming.hn.cn/index.php/2025/09/
description: 健康快乐每一天
items: TableDaoRelationship使用场景

TableDaoRelationship使用场景
type: item
date: 2025-09-17T01:53:00+00:00
description: 一般的ID、Name：new TableDaoRelationship(nameof(PayOrder.User), UserDAO.Instance.TableName)一般的ID、Name、Value：new TableDaoRelationship(nameof(PayOrder.Merchant), MerchantDAO.Instance.TableName).SetOtherFiledsAsIdNameValue(nameof(Merchant.Name), nameof(Merchant.MchId))一般的ID、Value：new TableDaoRelationship(nameof(PayOrder.ProfitSharingPlanOrder), ProfitSharingPlanOrderDAO.Instance.TableName).SetOtherFiledsAsIdValue(nameof(ProfitSharingPlanOrder.Status))主表ID和关联表ID重点在于：SetSelfFieldAliasnew TableDaoRelationship(nameof(PayOrder.ID), PayOrderTransactionDAO.Instance.TableName).SetSelfFieldAlias(nameof(PayOrder.Transaction)).SetOtherFileds(typeof(PayOrderTransactionInfo))指定关联表别名一般用于查询时需要使用关联表栏位作为查询条件重点在于：SetOtherTableAlias，使用时在生成查询条件时要指定Field。new TableDaoRelationship(nameof(PayOrder.ID), PayOrderTransactionDAO.Instance.TableName).SetSelfFieldAlias(nameof(PayOrder.Transaction)).SetOtherTableAlias(nameof(SQMIS.Model.PayOrderTransaction)).SetOtherFileds(typeof(PayOrderTransactionInfo)).AppendEqual(new Field(nameof(SQMIS.Model.PayOrderTransaction), nameof(SQMIS.Model.PayOrderTransaction.TransactionId)), this.TransactionID)多重关联时使用SetMoreLogicExpressions，可使用self和other来代替两个表的别名：new TableDaoRelationship(nameof(User.Principal), "RBAC_UserPrincipal").SetOtherFiledsAsIdNameValue("Name", "OuterID").SetMoreLogicExpressions(LogicExpression.BuildEqual(new Field("self", "Type"), new Field("other", "Type")))