LINQ to SQL的交易,并插入记录读取ID [英] LINQ to SQL transaction and read ID of inserted record

查看:169
本文介绍了LINQ to SQL的交易,并插入记录读取ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人可以explaoin我如何在数据库使用LINQ插入与交易和阅读记录的ID?

Can anybody explaoin me how to insert in database with Linq with transaction and read id of that record ?

推荐答案

如果您没有DBML设置,然后添加一个到您的项目结果
到A DBML添加到从Solution Explorer中的项目。结果
右键点击您的项目 - >去添加新项 - >选择LINQ to SQL类

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

要填写DBML与你的表,请访问:结果
查看 - >服务器资源管理器结果
展开您的数据库和拖动表格到DBML观众

To fill the DBML with your tables go to:
View -> Server Explorer
Expand your database and drag your tables onto the dbml viewer

然后:

DataClasses1DataContext db = new DataClasses1DataContext(myConnection);
db.Widgets.InsertOnSubmit(myWidget);

db.SubmitChanges();

//Here myWidget.Id will be set

这篇关于LINQ to SQL的交易,并插入记录读取ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆