Hello there,
I have this search page.
Based on selections of those inputs on the page, I am trying to query database.
The problem is I can't get the right order detail from the query.
Supposed to retrieve only orderdetail id = 13 when search for vendorId = 1 and order status = "Completed" But LINQ query brings more. Where is the problem?
Thanks in advance.
I have this search page.
C#:
<div class="m-4">
<div class="row g-6">
<div class="col-3">
<label class="form-label">Vendor</label>
<RadzenDropDownDataGrid TValue="int" AllowFiltering="true" AllowClear="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" FilterOperator="StringFilterOperator.Contains"
Data=@_vendors Count="5" TextProperty="Name" ValueProperty="Id" Change=@(args => OnChange(args))
Class="w-100"/>
</div>
<div class="col-3">
<label class="form-label">Order Date Start</label>
<RadzenDatePicker TValue="DateTime" DateFormat="d" Class="w-100" Change=@(args => OnStartDateChange(args)) />
</div>
<div class="col-3">
<label class="form-label">Order Date End</label>
<RadzenDatePicker TValue="DateTime" DateFormat="d" Class="w-100" Change=@(args => OnEndDateChange(args)) />
</div>
<div class="col-3">
<label class="form-label">Order Status</label>
<RadzenDropDown AllowClear="true" TValue="string" Class="w-100" Data=@orderStatusList Name="Status" Change=@(args => OnStatusChange(args))/>
</div>
</div>
<div class="mt-5">
<div class="d-flex flex-grow-1 justify-content-center align-items-center">
<button type="button" class="btn btn-primary w-25" @onclick="ExportExcel">
Orders Excel Export
</button>
</div>
</div>
</div>
Based on selections of those inputs on the page, I am trying to query database.
C#:
public async Task<IEnumerable<Order>> GetOrdersForExport(int vendorId,string status, DateTime? startDateTime, DateTime? endDateTime)
{
IQueryable<Order?> result = _db.Orders.Include(d => d.OrderDetails).ThenInclude(v => v.Vendor);
if (vendorId != null)
{
result = result.Where(d => d.OrderDetails.All(s => s.VendorId == vendorId));
}
if (status != null)
{
result = result.Where(dy => dy.Status == status);
}
return await result.ToListAsync();
}
The problem is I can't get the right order detail from the query.
C#:
SET IDENTITY_INSERT [dbo].[Orders] ON
INSERT INTO [dbo].[Orders] ([Id], [OrderDateTime], [CustomerName], [Status], [DoneBy]) VALUES (1, N'2022-06-07 16:46:21', N'customer1', N'Completed', N'test1111')
INSERT INTO [dbo].[Orders] ([Id], [OrderDateTime], [CustomerName], [Status], [DoneBy]) VALUES (2, N'2022-06-08 00:00:00', N'Vestel', N'Continues', N'Cenk')
INSERT INTO [dbo].[Orders] ([Id], [OrderDateTime], [CustomerName], [Status], [DoneBy]) VALUES (3, N'2022-07-09 00:00:00', N'Arçelik', N'Cancelled', N'Cavit')
INSERT INTO [dbo].[Orders] ([Id], [OrderDateTime], [CustomerName], [Status], [DoneBy]) VALUES (4, N'2022-08-08 23:31:59', N'Fener', N'Continues', N'Test')
INSERT INTO [dbo].[Orders] ([Id], [OrderDateTime], [CustomerName], [Status], [DoneBy]) VALUES (5, N'2022-08-08 23:37:54', N'Ümraniye', N'Continues', N'Ümraniye')
INSERT INTO [dbo].[Orders] ([Id], [OrderDateTime], [CustomerName], [Status], [DoneBy]) VALUES (6, N'2022-08-04 23:43:28', N'Bruma', N'Completed', N'Gustova')
INSERT INTO [dbo].[Orders] ([Id], [OrderDateTime], [CustomerName], [Status], [DoneBy]) VALUES (7, N'2022-09-09 13:16:36', N'Custom', N'Completed', N'Test')
INSERT INTO [dbo].[Orders] ([Id], [OrderDateTime], [CustomerName], [Status], [DoneBy]) VALUES (8, N'2022-08-09 13:21:14', N'Tsubasa', N'Continues', N'Employee')
INSERT INTO [dbo].[Orders] ([Id], [OrderDateTime], [CustomerName], [Status], [DoneBy]) VALUES (9, N'2022-10-27 13:37:36', N'New Customer', N'Completed', N'Test')
INSERT INTO [dbo].[Orders] ([Id], [OrderDateTime], [CustomerName], [Status], [DoneBy]) VALUES (10, N'2022-08-18 13:36:28', N'Wonderland', N'Continues', N'test')
INSERT INTO [dbo].[Orders] ([Id], [OrderDateTime], [CustomerName], [Status], [DoneBy]) VALUES (11, N'2022-08-20 14:12:44', N'Schumacher', N'Continues', N'Ferrari')
SET IDENTITY_INSERT [dbo].[Orders] OFF
SET IDENTITY_INSERT [dbo].[OrdersDetail] ON
INSERT INTO [dbo].[OrdersDetail] ([Id], [ProductCode], [ProductName], [Quantity], [CostRatio], [UnitCost], [TotalBuyPrice], [TotalSellPrice], [ShippingNumber], [Status], [TrackingNumber], [Description], [OrderId], [VendorId], [Currency], [BuyUnitPrice], [SellUnitPrice]) VALUES (4, N'1', N'r', 45, 27, 0, 56, 4, N'shipment', N'Completed', N'001', N'desc', 1, 2, N'Dolar', 4.5, 5.3)
INSERT INTO [dbo].[OrdersDetail] ([Id], [ProductCode], [ProductName], [Quantity], [CostRatio], [UnitCost], [TotalBuyPrice], [TotalSellPrice], [ShippingNumber], [Status], [TrackingNumber], [Description], [OrderId], [VendorId], [Currency], [BuyUnitPrice], [SellUnitPrice]) VALUES (5, N'12345-ABCN', N'Ipad', 5, 10, 1000, 1000, 1500, N'S1', N'Getting ready', N'T11111', N'description1', 2, 1, N'TL', 0, 0)
INSERT INTO [dbo].[OrdersDetail] ([Id], [ProductCode], [ProductName], [Quantity], [CostRatio], [UnitCost], [TotalBuyPrice], [TotalSellPrice], [ShippingNumber], [Status], [TrackingNumber], [Description], [OrderId], [VendorId], [Currency], [BuyUnitPrice], [SellUnitPrice]) VALUES (6, N'0000-DDDD', N'Modem', 6, 15, 200, 150, 225, N'S2', N'Getting ready', N'T11112', N'description2', 2, 2, N'TL', 0, 0)
INSERT INTO [dbo].[OrdersDetail] ([Id], [ProductCode], [ProductName], [Quantity], [CostRatio], [UnitCost], [TotalBuyPrice], [TotalSellPrice], [ShippingNumber], [Status], [TrackingNumber], [Description], [OrderId], [VendorId], [Currency], [BuyUnitPrice], [SellUnitPrice]) VALUES (7, N'98937-OPSKJ', N'ZTE', 7, 10, 5000, 4500, 5500, N'S3', N'Getting ready', N'T11113', N'description3', 2, 1, N'TL', 0, 0)
INSERT INTO [dbo].[OrdersDetail] ([Id], [ProductCode], [ProductName], [Quantity], [CostRatio], [UnitCost], [TotalBuyPrice], [TotalSellPrice], [ShippingNumber], [Status], [TrackingNumber], [Description], [OrderId], [VendorId], [Currency], [BuyUnitPrice], [SellUnitPrice]) VALUES (8, N'11111-YUSH', N'Laptop', 8, 6, 50, 50, 75, N'S4', N'Cancelled', N'T11114', N'description1', 3, 2, N'Dolar', 0, 0)
INSERT INTO [dbo].[OrdersDetail] ([Id], [ProductCode], [ProductName], [Quantity], [CostRatio], [UnitCost], [TotalBuyPrice], [TotalSellPrice], [ShippingNumber], [Status], [TrackingNumber], [Description], [OrderId], [VendorId], [Currency], [BuyUnitPrice], [SellUnitPrice]) VALUES (9, N'0090', N'Knife', 154, 30, 0, 700, 343, N'test', N'Completed', N'ueı9q9u', N'test', 1, 2, N'Euro', 5, 7.5)
INSERT INTO [dbo].[OrdersDetail] ([Id], [ProductCode], [ProductName], [Quantity], [CostRatio], [UnitCost], [TotalBuyPrice], [TotalSellPrice], [ShippingNumber], [Status], [TrackingNumber], [Description], [OrderId], [VendorId], [Currency], [BuyUnitPrice], [SellUnitPrice]) VALUES (10, N'4', N'mouse', 10, 10, 0, 10, 10, N's', N'Cancelled', N't', N'd', 3, 1, N'Euro', 0, 0)
INSERT INTO [dbo].[OrdersDetail] ([Id], [ProductCode], [ProductName], [Quantity], [CostRatio], [UnitCost], [TotalBuyPrice], [TotalSellPrice], [ShippingNumber], [Status], [TrackingNumber], [Description], [OrderId], [VendorId], [Currency], [BuyUnitPrice], [SellUnitPrice]) VALUES (11, N'rrrrrrrr', N'tank palet', 8878, 40, 0, 288, 39, N'trk*0292', N'Getting ready', N'79ıwowu998', N'desc', 4, 1, N'Dolar', 0, 0)
INSERT INTO [dbo].[OrdersDetail] ([Id], [ProductCode], [ProductName], [Quantity], [CostRatio], [UnitCost], [TotalBuyPrice], [TotalSellPrice], [ShippingNumber], [Status], [TrackingNumber], [Description], [OrderId], [VendorId], [Currency], [BuyUnitPrice], [SellUnitPrice]) VALUES (12, N'11112', N'ccccc2', 4, 4, 0, 4, 4, N'3332', N'In warehouse', N'3332', N'ttt', 9, 3, N'Euro', 0, 0)
INSERT INTO [dbo].[OrdersDetail] ([Id], [ProductCode], [ProductName], [Quantity], [CostRatio], [UnitCost], [TotalBuyPrice], [TotalSellPrice], [ShippingNumber], [Status], [TrackingNumber], [Description], [OrderId], [VendorId], [Currency], [BuyUnitPrice], [SellUnitPrice]) VALUES (13, N'444', N'rrrr', 2, 2, 0, 2, 2, N'ttt', N'Getting ready', N'5444', N'g', 9, 1, N'Dolar', 0, 0)
INSERT INTO [dbo].[OrdersDetail] ([Id], [ProductCode], [ProductName], [Quantity], [CostRatio], [UnitCost], [TotalBuyPrice], [TotalSellPrice], [ShippingNumber], [Status], [TrackingNumber], [Description], [OrderId], [VendorId], [Currency], [BuyUnitPrice], [SellUnitPrice]) VALUES (14, N'rrr', N'tttt', 5, 15, 0, 8, 9, N'uuu', N'At customs', N'6454', N'gtdd', 10, 1, N'Dolar', 0, 0)
INSERT INTO [dbo].[OrdersDetail] ([Id], [ProductCode], [ProductName], [Quantity], [CostRatio], [UnitCost], [TotalBuyPrice], [TotalSellPrice], [ShippingNumber], [Status], [TrackingNumber], [Description], [OrderId], [VendorId], [Currency], [BuyUnitPrice], [SellUnitPrice]) VALUES (15, N'2345', N'Cenk', 10, 13, 0, 0, 0, N'0000', N'Getting ready', N'0000', N'desc', 1, 3, N'TL', 3, 3.8)
INSERT INTO [dbo].[OrdersDetail] ([Id], [ProductCode], [ProductName], [Quantity], [CostRatio], [UnitCost], [TotalBuyPrice], [TotalSellPrice], [ShippingNumber], [Status], [TrackingNumber], [Description], [OrderId], [VendorId], [Currency], [BuyUnitPrice], [SellUnitPrice]) VALUES (16, N'3444', N'car', 1, 22, 0, 0, 0, N'ttt', N'Shipped', N'4444', N'd', 11, 2, N'Dolar', 150000, 175000)
INSERT INTO [dbo].[OrdersDetail] ([Id], [ProductCode], [ProductName], [Quantity], [CostRatio], [UnitCost], [TotalBuyPrice], [TotalSellPrice], [ShippingNumber], [Status], [TrackingNumber], [Description], [OrderId], [VendorId], [Currency], [BuyUnitPrice], [SellUnitPrice]) VALUES (17, N'8', N'd', 2, 4, 0, 0, 0, N'd', N'At customs', N'r', N'r', 11, 3, N'TL', 2, 10)
SET IDENTITY_INSERT [dbo].[OrdersDetail] OFF
Supposed to retrieve only orderdetail id = 13 when search for vendorId = 1 and order status = "Completed" But LINQ query brings more. Where is the problem?
Thanks in advance.