Click here to Skip to main content
15,895,656 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two tables, one for purchase master data e.g purchaseid, date, supplierId, bill amount, and the other one is Purchase_details table which contains purchaseID (ref of master table purchaseid) productid, qty, rate and amount.
Master table has purchaseid as primary key but details table nothing as primary key. PurchaseId may be repeat as per ordered products.

In linq to sql how i can save Details data without primary key.
I m new to linq to sql so detailed answer is more helpfull for me.
Please note, i have issue to save details data only due to no primary key.
Programming language is C#

What I have tried:

Waiting for response by codeproject members.
Posted
Updated 12-Feb-21 9:12am
Comments
[no name] 12-Feb-21 14:46pm    
ماهي sql


A-B-N Syria
[no name] 12-Feb-21 14:46pm    
ماهي sql

1 solution

Here is a code first example: LinqToSql code-first | LinqToSql Tutorial and Documentation[^]

Microsoft simple examples: What You Can Do With LINQ to SQL - ADO.NET | Microsoft Docs[^]

And here is a more elaborate CodeProject tutorial, see the part about the DataContext object:
LINQ to SQL: Basic Concepts and Features[^]
and the examples about updating / inserting records:
// update one product
Product bev1 = beverages.ElementAtOrDefault(10);
if (bev1 != null)
{
    Console.WriteLine("The price of {0} is {1}. Update to 20.0", 
                      bev1.ProductName, bev1.UnitPrice);
    bev1.UnitPrice = (decimal)20.00;
}
// submit the change to database
db.SubmitChanges();
Product newProduct = new Product {ProductName="new test product" };
db.Products.InsertOnSubmit(newProduct);
db.SubmitChanges();
 
Share this answer
 
v5

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