Entity Framework 查询 - 无法获取数据

Entity Framework Query - Unable to fetch data

我正在开发 WPF 应用程序并使用 Entity framework 6.0

我已经编写了以下查询来从数据库中获取数据,但无法获取任何数据:

var customersList = context.Customers.Include(x => x.ReturnedCustomerItems.Select(y => y.ReturnedLotItem)).Where(x => x.IsDeleted != false).ToList();

备注:

1. context: Database Context Object
2. Customers: DbSet for Customer's table
3. ReturnedCustomerItems: List of Customer Items to be returned.
4. ReturnedLotItem: Lot Item corresponding to Returned Customer Item. Each Customer Item will have a corresponding lot item..

以下是我为检查数据是否存在于数据库中而编写的 SQL 查询:

select * from 
transportapp.dbo.customer cust,
transportapp.dbo.ReturnedCustomerItem ret,
transportapp.dbo.ReturnedLotItem item
where 
cust.CustomerId = ret.CustomerId
and ret.BookingItemId = item.BookingItemId

作为输出,我得到了以下数据记录:

以下是由Entity Framework生成的Table结构:

CREATE TABLE [dbo].[ReturnedCustomerItem] (
    [BookingItemId]   INT             NOT NULL,
    [IsDeleted]       BIT             NOT NULL,
    [CustomerId]      INT             NOT NULL,
    [ReturnCharge]    DECIMAL (18, 2) NOT NULL,
    [DemurrageCharge] DECIMAL (18, 2) NOT NULL,
    [Weight]          DECIMAL (18, 2) NOT NULL,
    [Quantity]        INT             NOT NULL,
    [ReturnDate]      DATETIME        NOT NULL,
    [Status]          NVARCHAR (100)  NULL,
    CONSTRAINT [PK_dbo.ReturnedCustomerItem] PRIMARY KEY CLUSTERED ([BookingItemId] ASC),
    CONSTRAINT [FK_dbo.ReturnedCustomerItem_dbo.Customer_CustomerId] FOREIGN KEY ([CustomerId]) REFERENCES [dbo].[Customer] ([CustomerId]) ON DELETE CASCADE,
    CONSTRAINT [FK_dbo.ReturnedCustomerItem_dbo.ReturnedLotItem_BookingItemId] FOREIGN KEY ([BookingItemId]) REFERENCES [dbo].[ReturnedLotItem] ([BookingItemId])
);

CREATE TABLE [dbo].[ReturnedLotItem] (
    [BookingItemId]   INT             NOT NULL,
    [IsDeleted]       BIT             NOT NULL,
    [IsReturned]      BIT             NOT NULL,
    [ReturnCharge]    DECIMAL (18, 2) NOT NULL,
    [DemurrageCharge] DECIMAL (18, 2) NOT NULL,
    [Weight]          DECIMAL (18, 2) NOT NULL,
    [Quantity]        INT             NOT NULL,
    [LotId]           INT             NOT NULL,
    [LotItemId]       INT             NOT NULL,
    CONSTRAINT [PK_dbo.ReturnedLotItem] PRIMARY KEY CLUSTERED ([BookingItemId] ASC),
    CONSTRAINT [FK_dbo.ReturnedLotItem_dbo.BookingItem_BookingItemId] FOREIGN KEY ([BookingItemId]) REFERENCES [dbo].[BookingItem] ([BookingItemId]),
    CONSTRAINT [FK_dbo.ReturnedLotItem_dbo.ReturnedLot_LotId] FOREIGN KEY ([LotId]) REFERENCES [dbo].[ReturnedLot] ([LotId]) ON DELETE CASCADE,
    CONSTRAINT [FK_dbo.ReturnedLotItem_dbo.LotItem_LotItemId] FOREIGN KEY ([LotItemId]) REFERENCES [dbo].[LotItem] ([BookingItemId]) ON DELETE CASCADE
);

我无法调试我出错的 LINQ 表达式。需要帮助找出错误。

谢谢!!

发现我的愚蠢错误....

这是正确的 LINQ 表达式:

var customersList = context.Customers.Include(x => x.ReturnedCustomerItems.Select(y => y.ReturnedLotItem)).Where(x => x.IsDeleted == false).ToList();