-6

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
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

2 Answers2

0

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();
Victor Hugo Terceros
  • 2,969
  • 3
  • 18
  • 31
0
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();
Matthew Whited
  • 22,160
  • 4
  • 52
  • 69
  • When the SQL has table aliases such as `vUnit` and `title` I recommend using them as the range variables. – NetMage Sep 18 '17 at 17:50
  • I would recomend not making this mess at all. – Matthew Whited Sep 18 '17 at 17:53
  • 1
    That sounds like saying "I would recommend not programming"? Why are you on this site? If you think you have a better approach, shouldn't your answer reflect that? – NetMage Sep 18 '17 at 19:05