Convert this sql command to c# linq

421 views Asked by At

I am trying to convert this tSql command to linq query.
I want to group this columns.
Can you help me?

select  vUnit.FK_Unit_ID , Unit.unitNumber, unit.unitTitle , title.featureTitleName
from unit.UnitFeatureValue vUnit
inner join unit.Unit on vUnit.FK_Unit_ID = Unit.ID
inner join unit.FeatureTitle title on vUnit.FK_FeatureTitle_ID = title.ID
where vUnit.FK_Unit_ID = 15 and title.canMoreSelect = 1
group by vUnit.FK_Unit_ID ,unit.unitNumber, unit.unitTitle , title.featureTitleName
2

There are 2 answers

3
Matthew Whited On BEST ANSWER
var query = (
    from v in dbContext.UnitFeatureValue
    join u in dbContext.Unit on v.FK_Unit_ID equals u.ID
    join t in dbContext.FeatureTitle on v.FK_FeatureTitle_ID equals t.ID
    where v.FK_Unit_ID == 15 && t.canMoreSelect == 1
    select  new {
        v.FK_Unit_ID, 
        u.unitNumber, 
        u.unitTitle, 
        t.featureTitleName,
    }).Distinct();
5
Victor Hugo Terceros On

something like this

var result = (from v in vUnit 
join u in unit on v.FK_Unit_ID equals u.ID
join t in title on v.FK_FeatureTitle_ID equals t.ID
where v.FK_Unit_ID == 15 and t.canMoreSelect == 1
select new { v.FK_Unit_ID , u.unitNumber, u.unitTitle , t.featureTitleName }).ToList();