如何从 guid null 中使系统为空值?
How can I make the system empty value from the guid null?
在构建查询中,我有一个这样的查询:
var characteristicPrices = await scope.BuildQuery<CharacteristicPrice, CharacteristicVersion, CharacteristicPrice>((op, ccp, cv) => op.Select(op.AllColumnsOf(ccp))
.InnerJoin<CharacteristicVersion>(cv.Id == ccp.CharacteristicVersionId)
.Where(ccp.CountryId == request.CountryId && cv.VersionId == request.VersionId)).Get();
这里的 request.CountryId 字段对我来说是“000000...”。但我的查询无法正常工作,因为它的等效项在数据库中为空。如何将此值设置为空?
您可以直接将 null
传递给查询而不是 Guid.Empty
,或者您可以修改您的条件:
要么……
Guid? id = request.CountryId;
if (id==Guid.Empty)
{
id = null;
}
var characteristicPrices = await scope.BuildQuery<CharacteristicPrice, CharacteristicVersion, CharacteristicPrice>((op, ccp, cv) => op.Select(op.AllColumnsOf(ccp))
.InnerJoin<CharacteristicVersion>(cv.Id == ccp.CharacteristicVersionId)
.Where(ccp.CountryId == id && cv.VersionId == request.VersionId)).Get();
...或者...
var characteristicPrices = await scope.BuildQuery<CharacteristicPrice, CharacteristicVersion, CharacteristicPrice>((op, ccp, cv) => op.Select(op.AllColumnsOf(ccp))
.InnerJoin<CharacteristicVersion>(cv.Id == ccp.CharacteristicVersionId)
.Where((ccp.CountryId == request.CountryId || (request.CountryId==Guid.Empty && ccp.CountryId=null)) && cv.VersionId == request.VersionId)).Get();
在构建查询中,我有一个这样的查询:
var characteristicPrices = await scope.BuildQuery<CharacteristicPrice, CharacteristicVersion, CharacteristicPrice>((op, ccp, cv) => op.Select(op.AllColumnsOf(ccp))
.InnerJoin<CharacteristicVersion>(cv.Id == ccp.CharacteristicVersionId)
.Where(ccp.CountryId == request.CountryId && cv.VersionId == request.VersionId)).Get();
这里的 request.CountryId 字段对我来说是“000000...”。但我的查询无法正常工作,因为它的等效项在数据库中为空。如何将此值设置为空?
您可以直接将 null
传递给查询而不是 Guid.Empty
,或者您可以修改您的条件:
要么……
Guid? id = request.CountryId;
if (id==Guid.Empty)
{
id = null;
}
var characteristicPrices = await scope.BuildQuery<CharacteristicPrice, CharacteristicVersion, CharacteristicPrice>((op, ccp, cv) => op.Select(op.AllColumnsOf(ccp))
.InnerJoin<CharacteristicVersion>(cv.Id == ccp.CharacteristicVersionId)
.Where(ccp.CountryId == id && cv.VersionId == request.VersionId)).Get();
...或者...
var characteristicPrices = await scope.BuildQuery<CharacteristicPrice, CharacteristicVersion, CharacteristicPrice>((op, ccp, cv) => op.Select(op.AllColumnsOf(ccp))
.InnerJoin<CharacteristicVersion>(cv.Id == ccp.CharacteristicVersionId)
.Where((ccp.CountryId == request.CountryId || (request.CountryId==Guid.Empty && ccp.CountryId=null)) && cv.VersionId == request.VersionId)).Get();