开发者

ADO.Net EF, Class Inheritance LINQ-SQL Query Syntax?

I have the following ADO.Net Entities:

ADO.Net EF, Class Inheritance LINQ-SQL Query Syntax?

What I want to be able to do is Select a group of Games dependi开发者_如何学Cng on the LoanedTo ID. I.E Get all the games where LoanedTo == 1.

I cant quite seem to figure out how I would do this? Here is an example of how I tried it, but I get a list for LibraryItems and no option for .loanedTo (I hope this makes sense) Here is an example:

ADO.Net EF, Class Inheritance LINQ-SQL Query Syntax?

How Would I achieve this? What SQL Syntax? Thanks! :)


You'll want to filter your list of games by the fact that its LibraryItems collection of LibraryItem objects may contain at least one object with LoanTo = 1. Right?

Try to phrase your question precisely, because usually the reason why you're stuck is that you can't define the question clearly in the first place.

Alos, next time, type in your code. Don't just post a picture. It makes people who try to help you retype everything -- and this may turn off some people.

var games = from g in dataModel.MediaItems.OfType<Game>
            where g.LibraryItems.Any(item => item.LoanTo == 1)
            select g;


I often find it easier to start with the element I'm filtering with and then get the item I want (I'm also not a fan of the SQLy synthax):

var games = dataModel.LibraryItems.OfType<LibraryItem>()
   .Where(item => item.LoanTo == 1)
   .Select(item.MediaItem)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜