Click here to Skip to main content
15,905,781 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
basically I am getting an object ::

C#
OrderInfo thisOrder = await _context.OrderInfo
.Where(o => o.OrderNumber.Equals("ORDER_1") && 
            o.Business.BusinessId.Equals("BUSSINES_X"))
.Include(o => o.OrderLines)
.ThenInclude(oh => oh.OrderHistory)
.Include(o => o.OrderLines)
.ThenInclude(oh => oh.OrderLineMap)
.ThenInclude(olm => olm.DeviceIndex)
.Include(o => o.OrderLines)
.ThenInclude(oh => oh.CartonLineMap)
.ThenInclude(clm => clm.Carton)
.ThenInclude(c => c.Devices)
.Include(o => o.OrderProperties)
.Include(o => o.OrderLines)
.ThenInclude(oh => oh.Product)
.ThenInclude(op => op.ProductProperties)
.Include(o => o.Customer).SingleOrDefaultAsync();


I need to hold the record got here until I make all the changes, there is anyway to do that?



What I have tried:

nothing, there is any "linq" way to do that?
Posted
Updated 13-May-21 9:09am
v3

Here is an example from What You Can Do With LINQ to SQL - ADO.NET | Microsoft Docs[^]

// Northwnd inherits from System.Data.Linq.DataContext.
Northwnd nw = new Northwnd(@"northwnd.mdf");

Customer cust = new Customer();
cust.CompanyName = "SomeCompany";
cust.City = "London";
cust.CustomerID = "98128";
cust.PostalCode = "55555";
cust.Phone = "555-555-5555";
nw.Customers.InsertOnSubmit(cust);

// At this point, the new Customer object is added in the object model.
// In LINQ to SQL, the change is not sent to the database until
// SubmitChanges is called.
nw.SubmitChanges();
 
Share this answer
 
As far as I know, no, there is no equivalent in LINQ.

However, you can do a dummy update to the table in the beginning to acquire exclusive locks using the same conditions you would use in the select. Then do rest of the updates and once you're ready, commit the whole transaction. So instead of
 
Share this answer
 
There's no way to lock records in LINQ. If I understand what you're trying to do, you can wrap all of your work in a Transaction, though LINQ already does this on its own.

Working with transactions in Entity Framework and LINQ to SQL - Devart Blog[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900