Sql query help needed

Posts   
 
    
Jed
User
Posts: 38
Joined: 08-Oct-2010
# Posted on: 15-Dec-2010 08:07:34   

Hello I know that we arent meant to ask about converting sql to linq but what linq can i use with llblgen

select Min(id) as id, GroupName from dbo.radgroupcheck group by GroupName order by id

This is what i have but it throws a collolation error

from gc in metaData.Radgroupcheck orderby gc.Id group gc by gc.GroupName into a

Thanks in advance

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Dec-2010 10:12:36   

PLease post the error you get. And were is the select part of the linq query?

(edit) Here is a similar test query on Northwind:

    var q = from c in metaData.OrderDetail
            orderby c.Quantity
            group c by c.ProductId into g
            select new {g.Key, Max = g.Min(c => c.Quantity)};

(edit) But I guess you may need to order by the aggregated column "Min(Id)" rather than "Id" And in this case you should modify the above query to the following:

var q = from c in metaData.OrderDetail
        orderby c.Quantity
        group c by c.ProductId into g
        select new {ProductId = g.Key, MaxQuantity = g.Min(c => c.Quantity)} into results
        orderby results.MaxQuantity
        select results;
Jed
User
Posts: 38
Joined: 08-Oct-2010
# Posted on: 15-Dec-2010 12:51:19   

Thank You

But could you modify it to return an entity rather an anonymous type

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Dec-2010 16:19:11   
                var q = from c in metaData.OrderDetail
                        orderby c.Quantity
                        group c by c.ProductId into g
                        select new OrderDetailEntity() { ProductId = g.Key, Quantity = g.Min(c => c.Quantity) } into results
                        orderby results.Quantity
                        select results;