using System.Collections.Generic;
public static void Main(string[] args)
var Books = new List<Book>
new Book { Id = 12, Title = "Title 1" },
new Book { Id = 13, Title = "Title 2" },
new Book { Id = 14, Title = "Title 3" }
var Authors = new List<Author>
new Author {Id = 1, BookId = 12 , Name = "Steeve"},
new Author {Id = 2, BookId = 13 , Name = "Michel" },
new Author {Id = 3, BookId = 13 , Name = "Robert" }
var query = from book in Books
join author in Authors on book.Id equals author.BookId into gr1
select new { BookId = book.Id, AuthorId = gr1.LastOrDefault() == null ? "Null" : gr1.LastOrDefault().Id.ToString() };
var result = query.ToList();
foreach (var thisResult in result)
Console.WriteLine("{0}\t{1}", thisResult.BookId, thisResult.AuthorId);
public int BookId { get; set; }
public int Id { get; set; }
public string Name { get; set; }
public int Id { get; set; }
public string Title { get; set; }