How can we get the auto-generated identifier from the table when pasting?

How can we get the auto-generated identifier from the table when pasting?

I have three tables

Project

ProjectXMilestone

Milestone

and on the milestone insert. I also want to insert a row into the second table so that I need a MilestoneId? So how can I get it? I am using Linq.

+3
source share
2 answers

check that it is used for linq for sql

PractiseDataContext pDc = new PractiseDataContext();



// Here CustomerId is the Identity column(Primary key) in the 'CustomerDetails' table

CustomerDetail cust = new CustomerDetail();

cust.CustomerName = "LINQ to SQL";



pDc.CustomerDetails.InsertOnSubmit(cust);

pDc.SubmitChanges();



Response.Write(cust.CustomerId.ToString());
+3
source

LinqToSql, DataContext , , . 1: n Project ProjectMilestones, LinqToSql ProjectMilestones, .

- :

Project pr = new Project();
pr.Milestones = new List<ProjectMilestone>();

pr.Milestones.add(new ProjectMilestone());
pr.Milestones.add(new ProjectMilestone());

DataContext.InsertOnSubmit(pr);
pr.SubmitChanges();
0

Source: https://habr.com/ru/post/1746331/


All Articles