Good time, it became necessary to refer once to the MS SQL database, and you need to get the result of this type "Field Name, Number of all lines with this field name". using a sequence of calls to extend methods. I was able to generate such code (I have my own methods, comments are nearby). invoiceId - the variable passed to the method
var c = _repository.GetList<client_broker_invoice>(x => x.invoice_id == invoiceId); //получу Iquarable<client_broker_invoice> whare(x => x.invoice_id == invoiceId) //_repository.Query<> вернет: DB.Set<client_broker_invoice>().AsQueryable() var cc = _repository .Query<client_broker_invoice>() .Join( c, i => i.client_broker_id, o => o.client_broker_id, (i, o) => new { brokerId = i.client_broker_id //тут нужно количество записей где brokerId = i.client_broker_id }); It is necessary to somehow implement in addition to the sample the number of records where the brokerId is the same. Whether it is possible to make it to a DB. Those. don't do that
var check = cc.ToList(); var note = new {Id = check.First().brokerId, count = check.Count()}; The request is constructed in such a way that it returns 100% records where the brokerId is all the same
PS On sql I presented it like this:
select c1.client_broker_id as [brId], count(*) from client_broker_invoice c1 join (select c2.client_broker_id from client_broker_invoice c2 where c2.invoice_id = 205331) c3 on c1.client_broker_id = c3.client_broker_id group by c1.client_broker_id in this case, invoiceId = 205331