首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >处理queryover投影中的空值

处理queryover投影中的空值
EN

Stack Overflow用户
提问于 2012-05-03 23:14:28
回答 1查看 390关注 0票数 0

我有一个对应的,它有一个地址,可能分配了一个国家。

我该如何处理:

代码语言:javascript
复制
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。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-04 02:17:31

从您的话中,我可以假设您需要使用left join:

代码语言:javascript
复制
.Left.JoinQueryOver(() => invoiceAddres.Country, () => InvoiceAddressCountry)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10434294

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档