SELECT
[Extent1].[Id] AS [Id],
[Extent1].[Name] AS [Name],
[Extent1].[Description] AS [Description],
[Extent1].[IsVesselizable] AS [IsVesselizable],
[Extent1].[Price] AS [Price],
[Extent1].[CategoryId] AS [CategoryId],
[Extent2].[Id] AS [Id1],
[Extent2].[Name] AS [Name1]
FROM [dbo].[MenuItems] AS [Extent1]
INNER JOIN [dbo].[MenuItemCategories] AS [Extent2] ON [Extent1].[CategoryId] = [Extent2].[Id]
这是API函数:
// GET: api/MenuItems
public IQueryable<MenuItem> GetMenuItems()
{
return db.MenuItems.Include(m => m.Category);
}
和一些MenuItem类:
public class MenuItem
{
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
public decimal Price { get; set; }
[Required]
public int CategoryId { get; set; }
public MenuItemCategory Category { get; set; }
}
EF似乎应该让一切变得如此简单,但显然我在这里错过了一些东西。我不需要像这样制作最后一行,是吗?
public MenuItemCategory MenuItemCategory { get; set; }