2017-12-22 19 views
0

ダッパーでマルチマッピングを行うのが苦労しています。ここでダッパーマルチマッピングエラー

は私のコードです:SSMSで実行した場合

var contactDictionary = new Dictionary<Guid, Contact>(); 

IEnumerable<Contact> contacts = connection.Query<Contact, Activity, Contact>(
     @"SELECT ContactId, Title, FirstName, Surname, 
      AddressType.Type AS AddressType, Address.AddressLine1, Address.AddressLine2, Address.AddressLine3, Address.Town, Address.County, Address.Country, Address.Postcode, 
      EmailAddressType.Type AS EmailAddressType, EmailAddress.Email AS EmailAddress, 
      PhoneNumberType.Type As PhoneNumberType, PhoneNumber.Number AS PhoneNumber, 
      Direction.Type AS Direction, Activity.Summary, Activity.DateCompleted 
     FROM Contact 
      LEFT JOIN Address ON Contact.ContactPK = Address.ContactPK 
       LEFT JOIN AddressType ON Address.AddressTypePK = AddressType.AddressTypePK 
      LEFT JOIN EmailAddress ON Contact.ContactPK = EmailAddress.ContactPK 
       LEFT JOIN EmailAddressType ON EmailAddress.EmailAddressTypePK = EmailAddressType.EmailAddressTypePK 
      LEFT JOIN PhoneNumber ON Contact.ContactPK = PhoneNumber.ContactPK 
       LEFT JOIN PhoneNumberType ON PhoneNumber.PhoneNumberTypePK = PhoneNumberType.PhoneNumberTypePK 
      LEFT JOIN Activity ON Contact.ContactPK = Activity.ContactPK 
       LEFT JOIN Direction ON Activity.DirectionPK = Direction.DirectionPK 
     WHERE Contact.ContactId = @ContactId 
      AND Address.IsPrimary = 1 AND EmailAddress.IsPrimary = 1 AND PhoneNumber.IsPrimary = 1", 
     param:new { ContactId = contactId }, 
     map:(c, a) => 
     { 
      Contact contactEntry; 

      if (!contactDictionary.TryGetValue(c.ContactId, out contactEntry)) 
      { 
       contactEntry = c; 
       contactEntry.Activities = new List<Activity>(); 
       contactDictionary.Add(contactEntry.ContactId, contactEntry); 
      } 

      contactEntry.Activities.Add(a); 
      return contactEntry; 
     }, 
     splitOn: "ContactId") 
     .Distinct() 
     .ToList();  

ここではSQLの結果です: enter image description here

ここでコードが実行されるときに、私は取得していますエラーです: マルチを使用している場合は、 - マッピングAPIを使用すると、ID以外のキーがある場合、splitOnパラメータを設定できます パラメータ名:splitOn

私はsplitOnパラメータを指定したと思って本当に混乱していますか?

ご協力いただければ幸いです。

+2

splitOnパラメータは、両方のエンティティ(連絡先とアクティビティ)からプロパティを分離する方法をdapperに示す必要があります(オーダーされていると仮定して)アクティビティの最初のプロパティに設定する必要があります。 –

+0

splitOnを「Direction」に変更していただきありがとうございました –

答えて

0

splitOnパラメータは、両方のエンティティ(連絡先とアクティビティ)からプロパティを分離する方法をdapperに示すべきで、プロパティの最初のプロパティに設定する必要があります。