次のようなクラスを作成します。
public class Product {
public int ProductId { get; set; }
public string Name { get; set; }
public int CategoryId { get; set; }
public virtual Category Category { get; set; }
}
public class Category {
public int CategoryId { get; set; }
public string Name { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
そして、このクエリを使用して、ナビゲーションプロパティから結合が自動的に作成されます。
var query = from p in context.Products
select new {
ProductId = p.ProductId,
ProductName = p.Name,
CategoryName = p.Category.Name
};