In the Build Query I have a query like this:
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();
Here the request.CountryId field comes to me as "000000...". but my query is not working correctly because its equivalent is null in the database. How can I set this value to null?
CodePudding user response:
You can either directly pass null
to the query instead of Guid.Empty
or you could modify your condition:
Either...
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();
...or...
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();