Anyone know how to do this very basic subquery in LINQ?
(just trying to get the number of active contracts per vendor)
SELECT a.VendorID,a.Name, (SELECT count(Agency_Code) from Contracts b where b.Vendor_Code = a.VendorID) FROM Vendors a
yields:
10001 Becker Inc 4
10002 Carlisle Inc 0
etc

Riddhi ValechaRank #794 · 2.9K reputationPosted Sep 15, 2021, 12:17 PM EDT
Listint> IdsToFind = new Listint>() {2, 3, 4}; db.Users .Where(u => SqlMethods.Like(u.LastName, "%fra%")) .Where(u => db.CompanyRolesToUsers .Where(crtu => IdsToFind.Contains(crtu.CompanyRoleId)) .Select(crtu => crtu.UserId) .Contains(u.Id) )Try this method.https://stackoverflow.com/questions/418609/how-to-do-a-subquery-in-linq