简体   繁体   English

Linq:连接两个表

[英]Linq: Joining two tables

On my WPF Grid I am populating the following properties. 在我的WPF网格上,我正在填充以下属性。 The last two are coming from another table. 最后两个来自另一个表。 I would like to get the mapping rule from another table where sourceelementid in the transaction table equals the id of the messagefield table 我想获得从另一个表的映射规则,其中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;
}

but the Mapping rule column throws error. 但是“映射规则”列会引发错误。 Can some one help me ? 有人能帮我吗 ?

Here is a solution : 这是一个解决方案:

      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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM