Click here to Skip to main content
14,218,748 members
Rate this:
Please Sign up or sign in to vote.
this is the query
when i wrote it in Linq an error appear

select u.user_name ,max(l.last_action_date)
from Users u join system_log l on u.user_id = l.user_id
group by u.user_name


What I have tried:

the error in some case is
The specified LINQ expression contains references to queries that are associated with different contexts.
Posted
Updated 30-Apr-19 23:51pm
Comments
F-ES Sitecore 1-May-19 5:45am
   
You'll probably need to post the code you are using as that error doesn't sound like it is anything to do with your linq code.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Here's how you do max:

c# - Using Linq to SQL, how do I find min and max of a column in a table? - Stack Overflow[^]

Here is how you group by:

var totalProdcuts = from o in ctx.Orders
                    join p in ctx.Products on o.ProductId equals p.Id
                    group o.NumberOf by p.Name into g
                    select new { ProductName = g.Key, TotalOrdered = g.Sum() };
   
Comments
KhaledMohammad 1-May-19 6:08am
   
i can do it separately
but i need them together
Christian Graus 1-May-19 6:11am
   
The example has a sum. Replace it with Max.
KhaledMohammad 1-May-19 6:43am
   
The problem was to use two different dbcontext in the same linq
Now the problem has been solved by putting them in a list before doing linq
Thx
Christian Graus 1-May-19 16:54pm
   
yeah, that's what I would have said if the question had been clearer :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100