0

I have two tables. For simplistic reasons will call them Table A and Table B,

Table A:

ID int(PK)

customername varchar

customeraddy varchar

inservice boolean

etc varchar

etc varchar

Table B:

PKID int(PK)

ID int()

linename varchar

Just looking for a LINQ query that can select all values from a joined table of Table A and Table B on the ID column where inservice == "true" that omits any duplicates based on ID (because Table B has multiple duplicates of ID).

So far this is what i have:

from x in db.tableA
join y in db.tableB on x.id equals y.id
where x.inservice == "true"
select y);

1 Answers1

1

Assuming inservice is bool as in your table description and not string, and assuming you want both tableA and tableB rows where tableB has only one matching row,

var AjoinB = from x in db.tableA
             where x.inservice
             join y in db.tableB on x.id equals y.id
             group new { x, y } by x.id into xyg
             where xyg.Count() == 1
             select xyg;
NetMage
  • 26,163
  • 3
  • 34
  • 55
  • So I think the query works fine but i am getting an error saying that i can't implicitly convert type to the type defined in my ViewModel. this would be a ASP.NET MVC issue? – user10192547 Sep 11 '18 at 21:01
  • @user10192547 I think you will need to ask a separate question or show more code in this question explaining your purpose. – NetMage Sep 11 '18 at 21:35