Note that there are some explanatory texts on larger screens.

plurals
  1. POLinq Query returns 0 results, but should return 1
    text
    copied!<p>I have a SQL Server Compact Edition version 3.5 for a winforms app that is used as to store order information, but I have had a complaint from someone who is having issues where the detail isn't showing up after it has been finished and submitted, and by receiving the database of the user I can reproduce the problem, but I cannot figure out why. What I'm trying to figure out is why they aren't syncing up, because others do work just fine, and I have searched Stack Overflow and not found an answer that has worked for me.</p> <p>The results of linqpad/SSMS against the database I received are the same and bring up one row as a result of the following query (same query as entity framework profiler shows):</p> <pre><code>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 */ </code></pre> <p>However, if I use either of the following statements I get no results:</p> <pre><code>_orderDetails = ctx.OrderDetail.Where(o =&gt; o.OrderHeaderId == _order.Id).ToList(); _orderDetails = (from od in ctx.OrderDetail where od.OrderHeaderId == _order.Id select od).ToList(); </code></pre> <p>Order Header:</p> <pre><code>-- 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 </code></pre> <p>Order Detail:</p> <pre><code>-- 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 </code></pre> <p>Foreign Key:</p> <pre><code>-- 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 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload