开发者

Why is this query not supported in linq to entities?

I have a query like so.

var query = from o in _context.Orders
            join c in _context.Customers on o.CustomerId equals c.CustomerId
            orderby o.ShippedDate descending
            select new {OrderId = o.OrderId, Customer = c.FirstName};

I get the error "Only initializers, entity members, and entity navigation properties are supported". I swear I have been able to do this before but for the life of me can't understand what the issue is. I also can't restructure the query like this either.

var query =开发者_JS百科 from o in _context.Orders
            orderby o.ShippedDate descending
            select new {OrderId = o.OrderId, Customer = o.Customer.FirstName};

Baffled.


Try this:

var query = from o in _context.Orders
            join c in _context.Customers on o.CustomerId equals c.CustomerId
            orderby o.ShippedDate descending
            select new {o.OrderId, c.FirstName};


Try something like...

 var query = from o in _context.Orders
             join c in _context.Customers on o.CustomerId equals c.CustomerId
             orderby o.ShippedDate descending
             let OrderID = o.OrderID
             let Customer = c.FirstName
             select OrderID, Customer
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜