I have tried several things but it does not work. Basically, I want to add nested query on EF MVC3.
SQL Query:
select * from Book where Book_PK in ( select Book_Ref from Library
where Library_Ref=’18bd9526-f3e9-4d5b-86cd-ccfea64b6f7b’ )Book_PK is primary key of Book
Book_ref is foreign key to BookLibrary_Ref is just attribute to filter the Book_ref
I have 2 tables: Book and Library which are connected through foreign key.
I only have one input, which is id, but this is not the primary key of Library.
I have tried:
`
School.Models.Entities.SchoolAll db = new Models.Entities.SchoolAll(); // db consists whole database
var temp = db.Books.Where(e => e.Book_PK.Contains(db.Libraries.Where(f => f.Library_Ref == id))).ToList();
// where id is one of the field of Library`
each Library entity may have one or may Book entity. So, the result of the query is supposed to be as list. I need to save this list into one variable. Can anyone help me?
Successfully done, converting below query:
Into below entity framework:
Thanks stackoverflow