Can anybody explaoin me how to insert in database with Linq with transaction and read id of that record ?
If you don't have a DBML setup, then add one to your project.
To add a DBML to your project from Solution Explorer:
Right click on your project -> go to Add new Item -> select LINQ to SQL Classes
To fill the DBML with your tables go to:
View -> Server Explorer
Expand your database and drag your tables onto the dbml viewer
Then if your table is caleld Widget:
DataClasses1DataContext db = new DataClasses1DataContext(myConnection);
db.Widgets.InsertOnSubmit(myWidget);
db.SubmitChanges();
//Here myWidget.Id will be set
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With