在asp.net中使用C#通过Linq插入数据库之前,如何检查Unique [英] How to check Unique before insert in database through linq with C# in asp.net
本文介绍了在asp.net中使用C#通过Linq插入数据库之前,如何检查Unique的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用sqlcommand class write的帮助通过c#编码进行独特查找:
I was using for chek unique through c# coding with the help of sqlcommand class write :
select count(*) as v_count from dbo.BookTopic where TopicId <>1 and Topic=''abc''
很好...
但我想用linq编写此编码...请帮助我...
that is working fine...
But i want to write this coding in linq ...please help me...
Thank''s in Advance.
推荐答案
我假设您有一个名为BookTopic
的集合类.然后,这就是LINQ中SQL查询的样子.
I am assuming that you have a collection class calledBookTopic
. Then here is what the SQL query will look like in LINQ.
int count = (from bt in new BookTopic()
where !bt.TopicId.Equals(1) && bt.Topic.Equals("abc")
select bt).ToList().Count;
希望对您有所帮助.
I hope this helps you well.
u可以在LINQ中使用条件计数
看到此链接
http://msdn.microsoft.com/en-us/vcsharp/aa336747#countConditional [ ^ ]
u can use conditional count in LINQ
see this link
http://msdn.microsoft.com/en-us/vcsharp/aa336747#countConditional[^]
这篇关于在asp.net中使用C#通过Linq插入数据库之前,如何检查Unique的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文