2012-05-03 73 views
0

我有一個對應地址,它有一個地址,可能有一個國家分配。在查詢溢出投影中處理空值

如何處理這個問題:

InvoiceAddress invoiceAddres = null; 
Country InvoiceAddressCountry = null; 
Counterpart counterpart = null; 
CounterpartTabDTO result = null; 

// projections for DTO-mapping 
var projections = new[] 
         { 
          Projections.Property(() => counterpart.CounterpartId).WithAlias(() => result.InternalID), 
          Projections.Property(() => counterpart.GlobalCounterpartId).WithAlias(() => result.BasicInfo_GlobalCounterpartyID), 
          Projections.Property(() => counterpart.Name).WithAlias(() => result.BasicInfo_Name), 
          Projections.Property(() => counterpart.ShortName).WithAlias(() => result.BasicInfo_ShortName), 
          Projections.Property(() => counterpart.PhoneNumber).WithAlias(() => result.BasicInfo_Telephone), 
          Projections.Property(() => counterpart.Webpage).WithAlias(() => result.BasicInfo_WWW), 
          Projections.Property(() => counterpart.Language).WithAlias(() => result.BasicInfo_Language), 
          Projections.Property(() => counterpart.VAT).WithAlias(() => result.BasicInfo_VAT), 
          Projections.Property(() => counterpart.CompanyRegistrationNumber).WithAlias(() => result.BasicInfo_CompanyRegistationno), 
          Projections.Property(() => invoiceAddres.Name).WithAlias(() => result.BasicInfo_InvoiceAddressContactPerson), 
          Projections.Property(() => invoiceAddres.Street).WithAlias(() => result.BasicInfo_InvoiceAddressAddress), 
          Projections.Property(() => invoiceAddres.PostalCode).WithAlias(() => result.BasicInfo_InvoiceAddressPostalCode), 
          Projections.Property(() => invoiceAddres.City).WithAlias(() => result.BasicInfo_InvoiceAddressCity), 
          Projections.Property(() => invoiceAddres.Area).WithAlias(() => result.BasicInfo_InvoiceAddressArea), 
          Projections.Property(() => InvoiceAddressCountry.PrintableName).WithAlias(() => result.BasicInfo_InvoiceAddressCountry), 
          Projections.Property(() => invoiceAddres.Department).WithAlias(() => result.BasicInfo_InvoiceAddressDepartment), 
          Projections.Property(() => invoiceAddres.Fax).WithAlias(() => result.BasicInfo_InvoiceAddressFax), 
          Projections.Property(() => invoiceAddres.MainEmail).WithAlias(() => result.BasicInfo_InvoiceAddressEmail), 
         }; 
var query = Session.QueryOver(() => counterpart) 
    .JoinQueryOver<InvoiceAddress>(x => x.InvoiceAddresses,() => invoiceAddres) 
    .Where(x => x.IsDefault) 
    .JoinQueryOver<Country>(() => invoiceAddres.Country,() => InvoiceAddressCountry) 
    .Select(projections); 

問題是InvoiceAddressCountry,這可能是零。如果發生這種情況,我希望result.BasicInfo_InvoiceAddressCountry屬性保持爲空。 要澄清,上述代碼不起作用。它不能處理null。

回答

1

從你的話,我可以假設你需要使用左側加入:

.Left.JoinQueryOver(() => invoiceAddres.Country,() => InvoiceAddressCountry)