2015-08-06 3 views
0

Я застреваю с проблемой в nHibernate.I есть представление, которое имеет несколько записей в таблице, соответствующей одному идентификатору уведомления. Например, для уведомления id = 1 несколько записей есть:Nhibernate Duplicate data is coming coming, mapping issue

Ниже мой п отображение зимуют class.It наследует от Emailnotification base.which имеет все основные свойства

Ниже мой класс домена для просмотра:

public partial class vwNotificationPolicyDeliveryCoverLetters : EmailNotificationBase 
{ 
    public vwNotificationPolicyDeliveryCoverLetters() 
    { 
     //ReasonOfInAccuracy = new List<vwNotificationInaccuracyFailureReasons>(); 
     EmailNotificationBase = new List<EmailNotificationBase>(); 
    } 


    public virtual long NotificationId 
    { 
     get; 
     set; 
    } 
    public virtual int? PolicyAccurateLookupId 
    { 
     get; 
     set; 
    } 
    public virtual string PolicyCheckBy 
    { 
     get; 
     set; 
    } 

    public virtual string SendOnBehalfOf 
    { 
     get; 
     set; 
    } 
    public virtual string InAccuracyComments 
    { 
     get; 
     set; 
    } 
    public virtual DateTime? PolicyCheckDate 
    { 
     get; 
     set; 
    } 
    public virtual string ReasonOfInAccuracy 
    { 
     get; 
     set; 
    } 


    public virtual string PolicyNumber 
    { 
     get; 
     set; 
    } 

    public virtual string PolicyLobCode 
    { 
     get; 
     set; 
    } 
    public virtual string PolicyDescription 
    { 
     get; 
     set; 
    } 
    public virtual string PolicyType 
    { 
     get; 
     set; 
    } 

    public virtual DateTime? PolicyEffectiveDate 
    { 
     get; 
     set; 
    } 

    public virtual double? PolicyId 
    { 
     get; 
     set; 
    } 

    public virtual string ContactName 
    { 
     get; 
     set; 
    } 
    public virtual string DeliveryContactEmail 
    { 
     get; 
     set; 
    } 
    public virtual string SendOnBehalfOfEmailAddress 
    { 
     get; 
     set; 
    } 
    public virtual long DeliveryContactId 
    { 
     get; 
     set; 
    } 
    public virtual DateTime? PolicyExpirationDate 
    { 
     get; 
     set; 
    } 

    public virtual IList<EmailNotificationBase> EmailNotificationBase 
    { 
     get; 
     set; 
    } 

    public override bool Equals(object obj) 
    { 
     if (ReferenceEquals(this, obj)) 
      return true; 

     return Equals(obj as vwNotificationPolicyDeliveryCoverLetters); 
    } 

    public virtual bool Equals(vwNotificationPolicyDeliveryCoverLetters obj) 
    { 
     if (obj == null) return false; 

     if (Equals(Action, obj.Action) == false) return false;    
     if (Equals(Comments, obj.Comments) == false) return false; 
     if (Equals(Link, obj.Link) == false) return false;   
     if (Equals(NotificationId, obj.NotificationId) == false) return false; 
     if (Equals(NotificationIndicator, obj.NotificationIndicator) == false) return false; 
     if (Equals(NotificationStatus, obj.NotificationStatus) == false) return false; 
     if (Equals(NotificationType, obj.NotificationType) == false) return false;   
     if (Equals(RequestState, obj.RequestState) == false) return false; 
     if (Equals(ServiceRequestId, obj.ServiceRequestId) == false) return false; 
     if (Equals(ServiceRequestNumber, obj.ServiceRequestNumber) == false) return false;   
     if (Equals(ClientName, obj.ClientName) == false) return false; 
     if (Equals(ClientNumber, obj.ClientNumber) == false) return false; 
     if (Equals(PolicyId, obj.PolicyId) == false) return false; 
     if (Equals(PolicyNumber, obj.PolicyNumber) == false) return false; 
     if (Equals(PolicyLobCode, obj.PolicyLobCode) == false) return false; 
     if (Equals(PolicyDescription, obj.PolicyDescription) == false) return false; 
     if (Equals(PolicyType, obj.PolicyType) == false) return false; 
     if (Equals(ServicingLocation, obj.ServicingLocation) == false) return false; 
     if (Equals(PolicyEffectiveDate, obj.PolicyEffectiveDate) == false) return false; 
     if (Equals(ContactName, obj.ContactName) == false) return false; 
     if (Equals(DeliveryContactEmail, obj.DeliveryContactEmail) == false) return false; 
     if (Equals(SendOnBehalfOfEmailAddress, obj.SendOnBehalfOfEmailAddress) == false) return false; 
     if (Equals(DeliveryContactId, obj.DeliveryContactId) == false) return false; 
     if (Equals(PolicyExpirationDate, obj.PolicyExpirationDate) == false) return false; 
     if (Equals(PolicyAccurateLookupId, obj.PolicyAccurateLookupId) == false) return false; 
     if (Equals(PolicyCheckBy, obj.PolicyCheckBy) == false) return false; 
     if (Equals(PolicyCheckDate, obj.PolicyCheckDate) == false) return false; 

     if (Equals(ReasonOfInAccuracy, obj.ReasonOfInAccuracy) == false) return false; 
     if (Equals(InAccuracyComments, obj.InAccuracyComments) == false) return false; 
     if (Equals(SendOnBehalfOf, obj.SendOnBehalfOf) == false) return false; 

     return true; 
    } 

    public override int GetHashCode() 
    { 
     int result = 1; 

     result = (result * 397)^(Action != null ? Action.GetHashCode() : 0);    
     result = (result * 397)^(Comments != null ? Comments.GetHashCode() : 0); 
     result = (result * 397)^(Link != null ? Link.GetHashCode() : 0);   
     result = (result * 397)^NotificationId.GetHashCode(); 
     result = (result * 397)^(NotificationIndicator != null ? NotificationIndicator.GetHashCode() : 0); 
     result = (result * 397)^(NotificationStatus != null ? NotificationStatus.GetHashCode() : 0); 
     result = (result * 397)^(NotificationType != null ? NotificationType.GetHashCode() : 0);   
     result = (result * 397)^(RequestState != null ? RequestState.GetHashCode() : 0); 
     result = (result * 397)^(ServiceRequestId != null ? ServiceRequestId.GetHashCode() : 0); 
     result = (result * 397)^(ServiceRequestNumber != null ? ServiceRequestNumber.GetHashCode() : 0);   
     result = (result * 397)^(ClientName != null ? ClientName.GetHashCode() : 0); 
     result = (result * 397)^(ClientNumber != null ? ClientNumber.GetHashCode() : 0); 
     result = (result * 397)^(PolicyId != null ? PolicyId.GetHashCode() : 0); 
     result = (result * 397)^(PolicyNumber != null ? PolicyNumber.GetHashCode() : 0); 
     result = (result * 397)^(PolicyLobCode != null ? PolicyLobCode.GetHashCode() : 0); 
     result = (result * 397)^(PolicyDescription != null ? PolicyDescription.GetHashCode() : 0); 
     result = (result * 397)^(PolicyType != null ? PolicyType.GetHashCode() : 0); 
     result = (result * 397)^(ServicingLocation != null ? ServicingLocation.GetHashCode() : 0); 
     result = (result * 397)^(PolicyEffectiveDate != null ? PolicyEffectiveDate.GetHashCode() : 0); 
     result = (result * 397)^(ContactName != null ? ContactName.GetHashCode() : 0); 
     result = (result * 397)^(DeliveryContactEmail != null ? DeliveryContactEmail.GetHashCode() : 0); 
     result = (result * 397)^(SendOnBehalfOfEmailAddress != null ? SendOnBehalfOfEmailAddress.GetHashCode() : 0); 
     result = (result * 397)^DeliveryContactId.GetHashCode(); 
     result = (result * 397)^(PolicyAccurateLookupId != null ? PolicyAccurateLookupId.GetHashCode() : 0); 
     result = (result * 397)^(PolicyCheckBy != null ? PolicyCheckBy.GetHashCode() : 0); 
     result = (result * 397)^(PolicyCheckDate != null ? PolicyCheckDate.GetHashCode() : 0); 
     result = (result * 397)^(ReasonOfInAccuracy != null ? ReasonOfInAccuracy.GetHashCode() : 0); 
     result = (result * 397)^(PolicyExpirationDate != null ? PolicyExpirationDate.GetHashCode() : 0); 
     result = (result * 397)^(InAccuracyComments != null ? InAccuracyComments.GetHashCode() : 0); 
     result = (result * 397)^(SendOnBehalfOf != null ? SendOnBehalfOf.GetHashCode() : 0); 

     return result; 
    } 
} 
} 

Ниже приводится hbm-файл для базового класса .Inside что класс профсоюзом суб был создан для дочернего класса:

<?xml version="1.0" encoding="utf-8"?> 
<hibernate-mapping namespace="Aon.ATD.Domain.Model" assembly="Aon.ATD.DomainModel" xmlns="urn:nhibernate-mapping-2.2"> 
<class name="EmailNotificationBase" abstract="true"> 
    <id name="NotificationId" access="property" column="`NotificationId`"> 
     <generator class="assigned" /> 
    </id> 
<property name="ServiceRequestId" column="`ServiceRequestId`" /> 
<property name="ServiceRequestNumber" column="`ServiceRequestNumber`" /> 
<property name="ClientName" column="`ClientName`" /> 
<property name="ClientNumber" column="`ClientNumber`" /> 
<property name="AttachmentGroupId" column="`AttachmentGroupId`" /> 
<property name="Comments" column="`Comments`" /> 
<property name="NotificationType" column="`NotificationType`" /> 
<property name="NotificationStatus" column="`NotificationStatus`" />  
    <property name="Action" column="`Action`" /> 
<property name="Link" column="`Link`" /> 
<property name="NotificationIndicator" column="`Notification Indicator`" /> 
<property name="RequestState" column="`RequestState`" /> 
<property name="NotificationTypeId" column="`NotificationTypeId`" /> 
<property name="DistributionTypeId" column="`DistributionTypeId`" /> 
<property name="DistributionType" column="`DistributionType`" /> 
<property name="Office" column="`Office`" /> 
<property name="ModifiedDateTime" column="`ModifiedDateTime`" /> 
<property name="ServicingLocation" column="`ServicingLocation`" /> 
<property name="RequestCategoryId" column="`RequestCategoryId`" /> 
<property name="RequestTypeId" column="`RequestTypeId`" /> 

<many-to-one name="AttachmentGroup" class="AttachmentGroup" column="`AttachmentGroupId`" not-null="false" fetch="select" lazy="false" /> 
<!--<bag name="PolicyDeliveryCoverLetters" inverse="true" > 
    <key column="`NotificationId`" /> 
    <one-to-many class="vwNotificationPolicyDeliveryCoverLetters" /> 
</bag>--> 

<union-subclass name="VwEmailNotification" table="`VwEmailNotification`" /> 
    <union-subclass name="VwNotificationAudit" table="`vwNotificationAudit`"> 
    <property name="PolicyNumber" column="`PolicyNumber`" /> 
    <property name="LobCode" column="`LobCode`" /> 
    <property name="PolicyEffectiveDate" column="`PolicyEffectiveDate`" /> 
     <property name="PolicyId" column="`PolicyId`" /> 
    <property name="CarrierName" column="`CarrierName`" /> 
    <property name="DocumentType" column="`DocumentType`" /> 

    <!-- 
    <bag name="PITDSRsByPolicyID" inverse="true" lazy="false"> 
    <key column="`PolicyId`" /> 
    <one-to-many class="VwPITDSRByPolicyId" /> 
    </bag> 
    --> 

    </union-subclass> 
<union-subclass name="VwNotificationEndorsement" table="`vwNotificationEndorsement`"> 
    <property name="PolicyNumber" column="`PolicyNumber`" /> 
    <property name="LobCode" column="`LobCode`" /> 
    <property name="PolicyEffectiveDate" column="`PolicyEffectiveDate`" /> 
    <property name="PolicyId" column="`PolicyId`" /> 
    <property name="CarrierName" column="`CarrierName`" /> 
</union-subclass> 
<union-subclass name="VwNotificationPolicy" table="`vwNotificationPolicy`"> 
    <property name="PolicyNumber" column="`PolicyNumber`" /> 
    <property name="LobCode" column="`LobCode`" /> 
    <property name="PolicyEffectiveDate" column="`PolicyEffectiveDate`" /> 
    <property name="PolicyId" column="`PolicyId`" /> 
    <property name="CarrierName" column="`CarrierName`" /> 
    <property name="DocumentType" column="`DocumentType`" /> 

    <!-- 
    <bag name="PITDSRsByPolicyID" inverse="true" lazy="false"> 
    <key column="`PolicyId`" /> 
    <one-to-many class="VwPITDSRByPolicyId" /> 
    </bag> 
    --> 

</union-subclass> 
<union-subclass name="VwNotificationNotARSAccount" table="`vwNotificationNotARSAccount`"> 
    <property name="PolicyNumber" column="`PolicyNumber`" /> 
    <property name="LobCode" column="`LobCode`" /> 
    <property name="PolicyEffectiveDate" column="`PolicyEffectiveDate`" /> 
    <property name="PolicyId" column="`PolicyID`" /> 
    <property name="CarrierName" column="`CarrierName`" /> 
    <property name="EmailAddress" column="`EmailAddress`" /> 
</union-subclass> 
<union-subclass name="VwNotificationOfficePend" table="`vwNotificationOfficePend`"> 
    <property name="PolicyNumber" column="`PolicyNumber`" /> 
    <property name="LobCode" column="`LobCode`" /> 
    <property name="PolicyEffectiveDate" column="`PolicyEffectiveDate`" /> 
    <property name="EmailAddress" column="`EmailAddress`" /> 
</union-subclass> 
<union-subclass name="VwNotificationNotAONServiced" table="`vwNotificationNotAONServiced`"> 
    <property name="PolicyNumber" column="`PolicyNumber`" /> 
    <property name="LobCode" column="`LobCode`" />  
    <property name="CarrierName" column="`CarrierName`" /> 
    <property name="CarrierGroupCode" column="`CarrierGroupCode`" /> 
</union-subclass> 
<union-subclass name="VwNotificationDocumentOutOfScope" table="`vwNotificationDocumentOutOfScope`"> 
    <property name="PolicyNumber" column="`PolicyNumber`" /> 
    <property name="LobCode" column="`LobCode`" /> 
    <property name="CarrierName" column="`CarrierName`" /> 
    <property name="DocumentType" column="`DocumentType`" /> 
    <property name="CarrierGroupCode" column="`CarrierGroupCode`" /> 
</union-subclass> 
<union-subclass name="VwNotificationDiscrepancy" table="`vwNotificationDiscrepancy`"> 
    <property name="Astindicator" column="`Astindicator`" />  
    <property name="PolicyId" column="`PolicyId`" />  
</union-subclass> 
<union-subclass name="VwNotificationPolicyDelivery" table="`vwNotificationPolicyDelivery`"> 
    <property name="PolicyNumber" column="`PolicyNumber`" /> 
    <property name="PolicyLobCode" column="`PolicyLobCode`" /> 
    <property name="PolicyEffectiveDate" column="`PolicyEffectiveDate`" /> 
    <property name="PolicyId" column="`PolicyID`" /> 
    <property name="PolicyDescription" column="`PolicyDescription`" /> 
    <property name="PolicyType" column="`PolicyType`" /> 
    </union-subclass> 

<union-subclass name="vwNotificationPolicyDeliveryCoverLetters" table="`vwNotificationPolicyDeliveryCoverLetters`"> 
    <property name="PolicyNumber" column="`PolicyNumber`" /> 
    <property name="PolicyLobCode" column="`PolicyLobCode`" /> 
    <property name="PolicyEffectiveDate" column="`PolicyEffectiveDate`" /> 
    <property name="PolicyId" column="`PolicyID`" /> 
    <property name="PolicyDescription" column="`PolicyDescription`" /> 
    <property name="PolicyType" column="`PolicyType`" /> 
    <property name="ContactName" column="`ContactName`" /> 
    <property name="DeliveryContactEmail" column="`DeliveryContactEmail`" /> 
    <property name="SendOnBehalfOfEmailAddress" column="`SendOnBehalfOfEmailAddress`" /> 
    <property name="DeliveryContactId" column="`DeliveryContactId`" /> 
    <property name="PolicyExpirationDate" column="`PolicyExpirationDate`" /> 
    <property name="PolicyAccurateLookupId" type="Int32" column="`PolicyAccurateLookupId`" /> 
    <property name="PolicyCheckBy" type="String" column="`PolicyCheckBy`" /> 
    <property name="PolicyCheckDate" type="DateTime" column="`PolicyCheckDate`" /> 
    <property name="ReasonOfInAccuracy" column="`ReasonOfInAccuracy`" /> 
    <property name="InAccuracyComments" column="`InAccuracyComments`" /> 
    <property name="SendOnBehalfOf" column="`SendOnBehalfOf`" /> 
    <property name="NotificationId" column="`NotificationId`" /> 
</union-subclass> 

При получении записей первая строка, соответствующая идентификатору уведомления, получает дублирование. Например, для уведомления id = 1 есть три строки. Если выборка записей 2-й и 3-й строки имеет те же данные, что и первая строка.

ответ

0

Ожидаемое поведение. NHibernate видит, что вторая и третья записи имеют одинаковый идентификатор, поэтому данные должны быть одинаковыми (id = identity). Он просто передает ссылку на уже созданный первый объект.

То, что вы действительно здесь есть один-ко-многим ассоциации стоимости объектов вместо накидной подкласса, поэтому модель его как:

class vwNotificationPolicyDeliveryCoverLetters : EmailNotificationBase 
{ 
    public virtual Notification Owner { get; set; } 

    //other properties 
} 

<class name="VwEmailNotification" table="`VwEmailNotification`" /> 
    <composite-id> 
    <key-many-to-one name="Owner" column="`notification_id`" /> 
    <key-property name="PolicyNumber" column="`PolicyNumber`" /> 
    <key-property name="LobCode" column="`LobCode`" /> 
    <key-property name="PolicyEffectiveDate" column="`PolicyEffectiveDate`" /> 
    <key-property name="PolicyId" column="`PolicyId`" /> 
    <key-property name="CarrierName" column="`CarrierName`" /> 
    <key-property name="DocumentType" column="`DocumentType`" /> 
    </composite-id> 
</class> 

compositeid по всем свойствам соответствует вашей равной реализации

Смежные вопросы