Linq: เข้าร่วมสองตาราง

บน WPF Grid ของฉัน ฉันกำลังเติมคุณสมบัติต่อไปนี้ สองคนสุดท้ายมาจากโต๊ะอื่น ฉันต้องการรับกฎการแมปจากตารางอื่นโดยที่ 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;
}

แต่คอลัมน์กฎการแมปแสดงข้อผิดพลาด ใครสามารถช่วยฉันได้บ้าง


person Ayda Sayed    schedule 06.06.2013    source แหล่งที่มา
comment
คุณช่วยโพสต์ข้อยกเว้นภายในได้ไหม   -  person Goanne    schedule 06.06.2013
comment
@Goanne นี่คือข้อผิดพลาด: 'char' ไม่มีคำจำกัดความสำหรับ 'SourceElementId' และไม่มีวิธีการขยาย 'SourceElementId' ที่ยอมรับอาร์กิวเมนต์แรกของประเภท 'char' สามารถพบได้ (คุณขาดคำสั่งการใช้หรือการอ้างอิงแอสเซมบลีหรือไม่   -  person Ayda Sayed    schedule 06.06.2013
comment
โอเค คุณตั้งใจจะเพิ่มอาการโคม่าตัวสุดท้ายก่อนที่จะปิดวงเล็บด้านในหรือไม่? msgFields.Id)), =› msgFields.Id))   -  person Goanne    schedule 06.06.2013
comment
นี่คือสิ่งที่ฉันมี: MappingRule = TransactionRuleList.Where(mapRule =› mapRule.MappingRule.Any(tr =› tr.SourceElementId == msgFields.Id)) }) .ToList();   -  person Ayda Sayed    schedule 06.06.2013
comment
ฉันพบว่าปัญหาคืออะไร ฉันจะโพสต์วิธีแก้ปัญหาในไม่ช้า! ขอบคุณทุกคน   -  person Ayda Sayed    schedule 06.06.2013


คำตอบ (1)


นี่คือวิธีแก้ปัญหา:

      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
person Ayda Sayed    schedule 06.06.2013