C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,273 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I am trying to get all the completed statuses except a specific Id. Here is how I tried but I got false. Where is the problem? I expect it to be true.
OrdersDetails.Where(x => x.OrderId == 12).All(c => c.Id != 93 && c.Status == "Completed");
OrdersDetails.Where(x => x.OrderId == 12 && x.Id != 93).All(c => c.Status == "Completed");
Here is the sample data:
USE [InventoryManagement]
GO
/****** Object: Table [dbo].[OrdersDetail] Script Date: 9.02.2023 12:25:40 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[OrdersDetail](
[Id] [int] IDENTITY(1,1) NOT NULL,
[ProductCode] [nvarchar](100) NOT NULL,
[ProductName] [nvarchar](250) NULL,
[Quantity] [int] NOT NULL,
[CostRatio] [float] NOT NULL,
[UnitCost] [float] NOT NULL,
[TotalBuyPrice] [float] NOT NULL,
[TotalSellPrice] [float] NULL,
[ShippingNumber] [nvarchar](150) NULL,
[Status] [nvarchar](max) NULL,
[TrackingNumber] [nvarchar](150) NULL,
[Description] [nvarchar](400) NULL,
[OrderId] [int] NOT NULL,
[VendorId] [int] NOT NULL,
[Currency] [nvarchar](max) NULL,
[BuyUnitPrice] [float] NOT NULL,
[SellUnitPrice] [float] NULL,
[CustomerOrderNumber] [nvarchar](max) NULL,
[CustomerStockCode] [nvarchar](max) NULL,
[IsActive] [int] NOT NULL,
[TotalUnitCost] [float] NULL,
[Warehouse] [nvarchar](50) NULL,
[PaymentStatus] [nvarchar](100) NULL,
[CompletionDateTime] [datetime2](7) NULL,
CONSTRAINT [PK_OrdersDetail] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[OrdersDetail] ON
GO
INSERT [dbo].[OrdersDetail] ([Id], [ProductCode], [ProductName], [Quantity], [CostRatio], [UnitCost], [TotalBuyPrice], [TotalSellPrice], [ShippingNumber], [Status], [TrackingNumber], [Description], [OrderId], [VendorId], [Currency], [BuyUnitPrice], [SellUnitPrice], [CustomerOrderNumber], [CustomerStockCode], [IsActive], [TotalUnitCost], [Warehouse], [PaymentStatus], [CompletionDateTime]) VALUES (92, N'rrr', NULL, 2, 1, 4.04, 8, 10, NULL, N'Completed', NULL, NULL, 11, 1, N'EURO', 4, 5, NULL, NULL, 1, 8.08, N'China Warehouse', N'Pending Payment', CAST(N'2023-02-04T00:00:00.0000000' AS DateTime2))
GO
INSERT [dbo].[OrdersDetail] ([Id], [ProductCode], [ProductName], [Quantity], [CostRatio], [UnitCost], [TotalBuyPrice], [TotalSellPrice], [ShippingNumber], [Status], [TrackingNumber], [Description], [OrderId], [VendorId], [Currency], [BuyUnitPrice], [SellUnitPrice], [CustomerOrderNumber], [CustomerStockCode], [IsActive], [TotalUnitCost], [Warehouse], [PaymentStatus], [CompletionDateTime]) VALUES (93, N'ABC-xxx45', NULL, 5, 4, 10.972000000000001, 52.75, 58.552500000000009, N'xxx', N'Warehouse', N'1', N'xxx', 12, 1, N'USD', 10.55, 11.710500000000002, N'def-xx999', N'abc-101', 1, 54.860000000000007, N'China Warehouse', N'Pending Payment', NULL)
GO
INSERT [dbo].[OrdersDetail] ([Id], [ProductCode], [ProductName], [Quantity], [CostRatio], [UnitCost], [TotalBuyPrice], [TotalSellPrice], [ShippingNumber], [Status], [TrackingNumber], [Description], [OrderId], [VendorId], [Currency], [BuyUnitPrice], [SellUnitPrice], [CustomerOrderNumber], [CustomerStockCode], [IsActive], [TotalUnitCost], [Warehouse], [PaymentStatus], [CompletionDateTime]) VALUES (94, N'ABC-11', NULL, 6, 8, 15.2534232, 84.74124, 508.44744000000003, NULL, N'Completed', N'2', NULL, 12, 2, N'USD', 14.12354, 84.74124, N'222', N'11', 1, 91.5205392, N'USA Warehouse', N'Paid', CAST(N'2023-02-09T00:00:00.0000000' AS DateTime2))
GO
INSERT [dbo].[OrdersDetail] ([Id], [ProductCode], [ProductName], [Quantity], [CostRatio], [UnitCost], [TotalBuyPrice], [TotalSellPrice], [ShippingNumber], [Status], [TrackingNumber], [Description], [OrderId], [VendorId], [Currency], [BuyUnitPrice], [SellUnitPrice], [CustomerOrderNumber], [CustomerStockCode], [IsActive], [TotalUnitCost], [Warehouse], [PaymentStatus], [CompletionDateTime]) VALUES (95, N'1', NULL, 7, 15, 23, 140, 161, NULL, N'Completed', N'0', NULL, 12, 4, N'USD', 20, 23, N'111777', N'0', 1, 161, N'China Warehouse', N'Pending Payment', CAST(N'2023-02-09T00:00:00.0000000' AS DateTime2))
GO
INSERT [dbo].[OrdersDetail] ([Id], [ProductCode], [ProductName], [Quantity], [CostRatio], [UnitCost], [TotalBuyPrice], [TotalSellPrice], [ShippingNumber], [Status], [TrackingNumber], [Description], [OrderId], [VendorId], [Currency], [BuyUnitPrice], [SellUnitPrice], [CustomerOrderNumber], [CustomerStockCode], [IsActive], [TotalUnitCost], [Warehouse], [PaymentStatus], [CompletionDateTime]) VALUES (96, N'1001x', NULL, 3, 4, 7.28, 21, 16.5, N'12', N'Completed', N'1111xxx', N'Factoryxx', 13, 4, N'TL', 7, 5.5, N'344', N'123', 1, 21.84, N'USA Warehouse', N'Paid', CAST(N'2023-02-08T00:00:00.0000000' AS DateTime2))
GO
INSERT [dbo].[OrdersDetail] ([Id], [ProductCode], [ProductName], [Quantity], [CostRatio], [UnitCost], [TotalBuyPrice], [TotalSellPrice], [ShippingNumber], [Status], [TrackingNumber], [Description], [OrderId], [VendorId], [Currency], [BuyUnitPrice], [SellUnitPrice], [CustomerOrderNumber], [CustomerStockCode], [IsActive], [TotalUnitCost], [Warehouse], [PaymentStatus], [CompletionDateTime]) VALUES (99, N'8888', NULL, 100, 8, 15.120000000000001, 1400, 1354, N'728ue', N'Completed', N'289e9ww', N'ueı292ıeıe', 12, 2, N'USD', 14, 13.54, N'dsfsfsfs', N'ı029wowk', 1, 1512, N'China Warehouse', N'Pending Payment', CAST(N'2023-02-09T00:00:00.0000000' AS DateTime2))
GO
SET IDENTITY_INSERT [dbo].[OrdersDetail] OFF
GO
ALTER TABLE [dbo].[OrdersDetail] ADD DEFAULT ((0.0000000000000000e+000)) FOR [BuyUnitPrice]
GO
ALTER TABLE [dbo].[OrdersDetail] ADD DEFAULT ((0)) FOR [IsActive]
GO
ALTER TABLE [dbo].[OrdersDetail] WITH CHECK ADD CONSTRAINT [FK_OrdersDetail_Orders_OrderId] FOREIGN KEY([OrderId])
REFERENCES [dbo].[Orders] ([Id])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[OrdersDetail] CHECK CONSTRAINT [FK_OrdersDetail_Orders_OrderId]
GO
ALTER TABLE [dbo].[OrdersDetail] WITH CHECK ADD CONSTRAINT [FK_OrdersDetail_Vendors_VendorId] FOREIGN KEY([VendorId])
REFERENCES [dbo].[Vendors] ([Id])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[OrdersDetail] CHECK CONSTRAINT [FK_OrdersDetail_Vendors_VendorId]
GO