首页 新闻 会员 周边

linq to entity 插入一条记录后,怎么获取插入 这条记录的id

0
悬赏园豆:5 [已解决问题] 解决于 2012-11-23 16:08

表结构

ID 自动增长

CustomerName 用户姓名

linq to Entity 新增代码

Customer customer = new Customer();
customer.CustomerName = txtReceiver.Text;
edm.AddToCustomer(customer);
edm.SaveChanges();

问题:怎么才能在新增完之后 得到自动增长的ID的值 

补充:是如何才能得到ID   

           int intID=customerID;

yellowshorts的主页 yellowshorts | 初学一级 | 园豆:162
提问于:2012-11-23 15:42
< >
分享
最佳答案
0

customer.Id 会被自动赋值。

收获园豆:5
Launcher | 高人七级 |园豆:45045 | 2012-11-23 16:02

不是 是要在后台得到最新的ID

yellowshorts | 园豆:162 (初学一级) | 2012-11-23 16:04

@yellowshorts: 

Customer customer = new Customer();
customer.CustomerName = txtReceiver.Text;
edm.AddToCustomer(customer);
edm.SaveChanges();

return customer.Id;

Launcher | 园豆:45045 (高人七级) | 2012-11-23 16:05

@Launcher: 可以了 谢谢哈 

yellowshorts | 园豆:162 (初学一级) | 2012-11-23 16:07
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册