如何使用LINQ仅在数据库中插入唯一记录 [英] how to insert only unique records in database using LINQ

查看:74
本文介绍了如何使用LINQ仅在数据库中插入唯一记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我有两个栏目

1st是employeeid

2nd是employeename





员工ID是主键...



但我也希望那个employeeename也是唯一的..所以我怎么能点击提交按钮.if员工姓名与其他colum相匹配..然后显示消息已经存在..





i想要LINQ中的解决方案

my question is i have two columns
1st is employeeid
2nd is employeename


employee id is primary key...

but i also want that employeename also unique..so how can i do on click of submit button.if employee name is match wid other colum..then message is display tht already exists..


i want thaat solution in LINQ

推荐答案







数据库:

你应该为柱employeesename创建一个唯一约束,这样你就可以确保employeesename在你的表中是唯一的。



代码:

您可以在生成插入语句之前验证表中是否存在该名称。



问候
Hi,


Database:
You should create a unique constraint for column employeename, this way, you will ensure that employeename is unique in your table.

Code:
You can verify if the name exists in the table before make the insert statement.

Regards


这篇关于如何使用LINQ仅在数据库中插入唯一记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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