Reputation: 2167
I have implemented a REST web service in c#. To connect on database, I have used EntityFramework.
I have this code:
private IQueryable<ClinicalDocumentDTO> getClinicalDoc(string cf)
{
if (cf != null)
{
return from p in db_data.CLINICAL_DOC
where p.CodiceFiscaleAssisito == cf
select new ClinicalDocumentDTO()
//select new CLINICAL_DOC
{
Code = p.Code,
CodeSystem = p.CodeSystem,
dateStart = ad.VerifyEffectiveTime,
dateEnd = ad.VerifyEffectiveTimeMax
}
}
}
Now I want to change this code, I have this field "dateStard" and "dateEnd", but on the database, I have three column (effetiveTime, effetiveTimeMin, effectiveTimeMax).
I want this:
if (effectiveTime == null) then
dateStart= effectiveTimeMin,
dateEnd = effectiveTimeMax
How can I do this in Entity Framework?
Upvotes: 0
Views: 42
Reputation: 4423
You can use ?:
operator in select as mentioned below:
return from p in db_data.CLINICAL_DOC
where p.CodiceFiscaleAssisito == cf
select new ClinicalDocumentDTO()
//select new CLINICAL_DOC
{
Code = p.Code,
CodeSystem = p.CodeSystem,
dateStart = p.effectiveTime == null ? effectiveTimeMin : ad.VerifyEffectiveTime,
dateEnd = p.effectiveTime == null ? effectiveTimeMax: ad.VerifyEffectiveTimeMax
}
PS: casing of variables is not checked. Please updated them accordingly.
Upvotes: 1