I have the below SQL query, Which I need to convert to LINQ. The SQL query:
select distinct a.DeliverableAdditionalFieldId, b.FieldName, b.CustomFieldType
from PrefixDeliverableAdditionalFieldsMapping as a, DeliverableAdditionalField as b
where a.DeliverableAdditionalFieldId = b.Id
and b.IsActive = 1
and a.PrefixId in (184,183)
I converted the sql query to LINQ which is below:
var prefixIds = "184, 183"
from prefix in context.PrefixDeliverableAdditionalFieldsMappings
join additionalField in context.DeliverableAdditionalFields on prefix.DeliverableAdditionalFieldId equals additionalField.Id
where additionalField.IsActive == true && prefixIds.Contains(prefix.PrefixId.ToString())
select new AdditionalCustomField
{
AdditionalFieldId = prefix.DeliverableAdditionalFieldId,
AdditionalFieldName = additionalField.FieldName,
FieldType = additionalField.CustomFieldType
}).Distinct().ToList()
For IN Operator of SQL, in LINQ I used the code : prefixIds.Contains(prefix.PrefixId.ToString(). Now I need to sure that this is OK. Please let me know is there any other alternative way?
And is there any alternate way to use distinct and the way I used, will it work?