0

我有一个用于存储订单信息的 winforms 应用程序的 SQL Server Compact Edition 3.5 版,但有人抱怨说,在完成并提交后详细信息未显示,通过接收用户的数据库,我可以重现问题,但我不知道为什么。我想弄清楚为什么他们没有同步,因为其他人工作得很好,我搜索了 Stack Overflow 并没有找到对我有用的答案。

linqpad/SSMS 针对我收到的数据库的结果是相同的,并且作为以下查询的结果显示一行(与实体框架分析器显示的查询相同):

SELECT [Extent1].[Id]                  AS [Id],
       [Extent1].[OrderHeaderId]       AS [OrderHeaderId],
       [Extent1].[Price]               AS [Price],
       [Extent1].[Quantity]            AS [Quantity],
       [Extent1].[OverridePrice]       AS [OverridePrice],
       [Extent1].[ShippingWeight]      AS [ShippingWeight],
       [Extent1].[ExtendedPrice]       AS [ExtendedPrice],
       [Extent1].[OrderId]             AS [OrderId],
       [Extent1].[ProductItemNo]       AS [ProductItemNo],
       [Extent1].[ProductItemNoTypeId] AS [ProductItemNoTypeId]
FROM   [OrderDetail] AS [Extent1]
WHERE  [Extent1].[OrderHeaderId] = 'eec06164-a052-4c23-9575-8fe1b80c8baa' /* @p__linq__0 */

但是,如果我使用以下任一语句,我不会得到任何结果:

_orderDetails = ctx.OrderDetail.Where(o => o.OrderHeaderId == _order.Id).ToList();

_orderDetails = (from od in ctx.OrderDetail
                 where od.OrderHeaderId == _order.Id
                 select od).ToList();

订单标题:

-- Creating table 'OrderHeader'
CREATE TABLE [OrderHeader] (
    [Id] uniqueidentifier  NOT NULL,
    [PONumber] nvarchar(4000)  NULL,
    [InternalOrderText] nvarchar(4000)  NULL,
    [TimeStamp] datetime  NOT NULL,
    [IOCTrackingNo] nvarchar(4000)  NULL,
    [CarrierCode] nvarchar(4000)  NULL,
    [HowEntered] nvarchar(4000)  NOT NULL,
    [MessageName] nvarchar(4000)  NOT NULL,
    [RepID] nvarchar(4000)  NOT NULL,
    [BatchID] nvarchar(4000)  NOT NULL,
    [Status] nvarchar(4000)  NOT NULL,
    [ApplicationVersion] nvarchar(4000)  NOT NULL,
    [CustomerAccountID] nvarchar(4000)  NOT NULL,
    [CustomerSubAccountID] nvarchar(4000)  NOT NULL,
    [SystemArrivalDate] datetime  NULL,
    [OrderId] int  NOT NULL
);
GO

-- Creating primary key on [Id] in table 'OrderHeader'
ALTER TABLE [OrderHeader]
ADD CONSTRAINT [PK_OrderHeader]
    PRIMARY KEY ([Id] );
GO

订单详情:

-- Creating table 'OrderDetail'
CREATE TABLE [OrderDetail] (
    [Id] uniqueidentifier  NOT NULL,
    [OrderHeaderId] uniqueidentifier  NOT NULL,
    [Price] decimal(18,2)  NOT NULL,
    [Quantity] int  NOT NULL,
    [OverridePrice] bit  NOT NULL,
    [ShippingWeight] decimal(18,3)  NOT NULL,
    [ExtendedPrice] decimal(18,2)  NOT NULL,
    [OrderId] int  NOT NULL,
    [ProductItemNo] nvarchar(4000)  NOT NULL,
    [ProductItemNoTypeId] uniqueidentifier  NOT NULL
);
GO

-- Creating primary key on [Id] in table 'OrderDetail'
ALTER TABLE [OrderDetail]
ADD CONSTRAINT [PK_OrderDetail]
    PRIMARY KEY ([Id] );
GO

外键:

-- Creating foreign key on [OrderHeaderId] in table 'OrderDetail'
ALTER TABLE [OrderDetail]
ADD CONSTRAINT [FK_OrderDetailOrderHeader]
    FOREIGN KEY ([OrderHeaderId])
    REFERENCES [OrderHeader]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderDetailOrderHeader'
CREATE INDEX [IX_FK_OrderDetailOrderHeader]
ON [OrderDetail]
    ([OrderHeaderId]);
GO
4

1 回答 1

0

我自己和其他几个人都无法弄清楚链接断开的原因,所以我决定将数据库更改为SQL CE 4.0因为能够使用int identity字段,从那以后我们就没有遇到过这个问题。

于 2013-06-06T14:03:11.257 回答