[英]Linq: Joining two tables
在我的WPF網格上,我正在填充以下屬性。 最后兩個來自另一個表。 我想獲得從另一個表的映射規則,其中sourceelementid
在交易表等於id
的的messagefield
表
public List<MessageFieldViewModel> GetAllViewModelMsgFields()
{
messageFieldVModel = messageField.GetAllMessageField().Select(msgFields => new MessageFieldViewModel
{
Id = msgFields.Id,
Code = msgFields.Code,
Name = msgFields.Name,
Position = msgFields.Position,
Length = msgFields.Length,
IsMapped = (transactionRuleList.Any(tr=> tr.SourceElementId ==msgFields.Id)),
MappingRule = transactionRuleList.Where(mapRule => mapRule.MappingRule.Any(tr=> tr.SourceElementId ==msgFields.Id)),
})
.ToList();
return messageFieldVModel;
}
但是“映射規則”列會引發錯誤。 有人能幫我嗎 ?
這是一個解決方案:
transactionRuleList = transationRuleViewModel.GetAllTranslationRules();
messageFieldVModel = messageField.GetAllMessageField().Select(msgFields => new MessageFieldViewModel
{
Id = msgFields.Id,
Code = msgFields.Code,
Name = msgFields.Name,
Position = msgFields.Position,
Length = msgFields.Length,
IsMapped = (transactionRuleList.Any(tr => tr.SourceElementId == msgFields.Id)),
MappingRule = transactionRuleList.Any(mapRule => mapRule.SourceElementId == msgFields.Id)?transactionRuleList.First(mapRule => mapRule.SourceElementId == msgFields.Id).MappingRule:null
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.