Hello I am trying to convert the following SQL statement into its LINQ equivalent and since I am really new to .net (coding for one day) i have gotten stuck on this for hours now.
SELECT *
FROM Books
WHERE BookID IN (SELECT BookID
FROM Borrows
WHERE UserID = 2)
This is the model
public class LibUser
{
[Key]
public int UserID { get; set; }
[Required, StringLength(50), Display(Name = "First Name")]
public string UserFirstName { get; set; }
[Required, StringLength(50), Display(Name = "Last Name")]
public string UserLastName { get; set; }
[Required, StringLength(10000), Display(Name = "Residence"), DataType(DataType.MultilineText)]
public string Adress { get; set; }
}
public class Book {
[Key]
public int BookID { get; set; }
public string Title { get; set; }
public string Author { get; set; }
public DateTime Published{ get; set; }
}
public class Borrowed {
[Key]
public int BorrowID { get; set; }
public int UserID { get; set; }
public int BookID { get; set; }
}
I would greatly appreciate anyones help.
EDIT
Context class
public class LibraryContext : DbContext
{
public LibraryContext()
: base("libromatic")
{
}
public DbSet<LibUser> LibUsers { get; set; }
public DbSet<Book> Books { get; set; }
public DbSet<Borrowed> Borrows { get; set; }
}