LINQ TO SQL中NOT IN怎么使用??

wuxin52115288 2013-08-04 10:07:01
最近需要写一个LINQ语句。用到not in ,小弟又是初学。 看了网上很多的帖子~ 说contain这个东东 怎么都点不出来~明天就是周1.一定要写出来~~但是还是不会~所以来跪求大神了。。求代码~~不用麻烦的 来个例子就好~~
...全文
182 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuxin52115288 2013-08-05
  • 打赏
  • 举报
回复
引用 2 楼 q107770540 的回复:
怎么点不出来了? 发点你的代码来看看 一般 !Contains()就是Not In
就是在!(这里写再写一个linq查询条件).contains 这里 。不出来 是不能在里面写子查询么?
wuxin52115288 2013-08-05
  • 打赏
  • 举报
回复
非常感谢~~~~各位的回答 对我帮助很大~谢谢了
q107770540 2013-08-05
  • 打赏
  • 举报
回复
 var query= from b in dataContext.employee
                        join c in dataContext.class_semester_ships
                        on b.PKEmpID equals c.FKHeadeTeacherID
                        select b.PKEmpID; //找出班主任ID

          var News = from a in dataContext.employee
			where !query.Contains(a.PKEmpID)
                         select a.PKEmpID;
wuxin52115288 2013-08-05
  • 打赏
  • 举报
回复
引用 2 楼 q107770540 的回复:
怎么点不出来了? 发点你的代码来看看 一般 !Contains()就是Not In
var New = from b in dataContext.employee from c in dataContext.class_semester_ships where b.PKEmpID == c.FKHeadeTeacherID select b.PKEmpID.ToString(); //找出班主任ID var News = from a in dataContext.employee select a.PKEmpID; 想在News里面写 not in ~
q107770540 2013-08-05
  • 打赏
  • 举报
回复
这要看你 . 前边的部分是什么类型的 有没有继承自IEnumerable接口
public static bool Contains<TSource>(
	this IEnumerable<TSource> source,
	TSource value
)
http://msdn.microsoft.com/en-us/library/bb352880.aspx
threenewbee 2013-08-04
  • 打赏
  • 举报
回复
除了Contains,也可以用Any/All int[] arrs=new int[]{1,2,3,4}; var query=from p in dbtable where !arrs.Contains(p.id) select p; 也可以写成 var query = dbtable.Where(x => arrs.All(y => y != x));
q107770540 2013-08-04
  • 打赏
  • 举报
回复
怎么点不出来了? 发点你的代码来看看 一般 !Contains()就是Not In
EnForGrass 2013-08-04
  • 打赏
  • 举报
回复
举个例子,查询table中id不为在1,2,3,4的数据 int[] arrs=new int[]{1,2,3,4}; var query=from p in dbtable where !arrs.Contains(p.id) select p;
关于LINQ的一本书籍,附上源码,喜欢请购买正版。 LINQ is the part of the .NET Framework that provides a generic approach to querying data from different data sources. It has quickly become the next must-have skill for .NET developers. Pro LINQ: Language Integrated Query in C# 2010 is all about code. Literally, this book starts with code and ends with code. Most books show the simplest examples of how to use a method, but they so rarely show how to use the more complex prototypes. This book is different. Demonstrating the overwhelming majority of LINQ operators and prototypes, it is a veritable treasury of LINQ examples. Rather than obscure the relevant LINQ principles in code examples by focusing on a demonstration application you have no interest in writing, this book cuts right to the chase of each LINQ operator, method, or class. However, where complexity is necessary to truly demonstrate an issue, the examples are right there in the thick of it. For example, code samples demonstrating how to handle concurrency conflicts actually create concurrency conflicts so you can step through the code and see them unfold. Face it, most technical books, while informative, are dull. LINQ need not be dull. Written with a sense of humor, this book will attempt to entertain you on your journey through the wonderland of LINQ and C# 2010. What you’ll learn How to leverage all the new LINQ relevant C# 2008 language features including extension methods, lambda expressions, anonymous data types, and partial methods. How to use LINQ to Objects to query in-memory data collections such as arrays, ArrayLists, and Lists to retrieve the data you want. Why some queries are deferred, how a deferred query can bite you, and how you can make deferred queries work for you. How to use LINQ to XML to revolutionize your creation, manipulation, and searching of XML data. How to query DataSets with LINQ to DataSet so you can coexist with legacy code and use LINQ to query databases other than SQL Server. How to query Databases with LINQ to SQL, write your own entity classes, and understand how to handle concurrency conflicts. Who this book is for This book is written for the proficient C# developer, but you do not need to be up on all the latest C# features to understand the material. When you finish this book, you will have a much greater understanding of the latest C# features. Table of Contents Hello LINQ C# Language Enhancements for LINQ LINQ to Objects Introduction Deferred Operators Nondeferred Operators LINQ to XML Introduction The LINQ to XML API LINQ to XML Operators Additional XML Capabilities LINQ to DataSet Operators Additional DataSet Capabilities LINQ to SQL Introduct ion LINQ to SQL Tips and Tools LINQ to SQL Database Operations LINQ to SQL Ent ity Classes The LINQ to SQL DataContext LINQ to SQL Concurrency Conflicts Additional LINQ to SQL Capabilities LINQ to Entities Introduction LINQ to Entities Operations LINQ to Entities Classes Parallel LINQ Introduction Using Parallel LINQ Parallel LINQ Operators
LINQ文学习资料和LINQ 随身参考手册,其LINQ 随身参考手册是英文版的,但内容不错。 LINQ 随身参考手册介绍:   Ready to take advantage of LINQ with C# 3.0? This guide has the detail you need to grasp Microsoft’s new querying technology, and concise explanations to help you learn it quickly. And once you begin to apply LINQ, the book serves as an on-the-job reference when you need immediate reminders. All the examples in the LINQ Pocket Reference are preloaded into LINQPad, the highly praised utility that lets you work with LINQ interactively. Created by the authors and free to download, LINQPad will not only help you learn LINQ, it will have you thinking in LINQ. This reference explains: LINQ’s key concepts, such as deferred execution, iterator chaining, and type inference in lambda expressions The differences between local and interpreted queries C# 3.0′s query syntax in detail-including multiple generators, joining, grouping, query continuations, and more Query syntax versus lambda syntax, and mixed syntax queries Composition and projection strategies for complex queries All of LINQ’s 40-plus query operators How to write efficient LINQ to SQL queries How to build expression trees from scratch All of LINQ to XML’s types and their advanced useLINQ promises to be the locus of a thriving ecosystem for many years to come. This small book gives you a huge head start. “The authors built a tool (LINQPad) that lets you experiment with LINQ interactively in a way that the designers of LINQ themselves don’t support, and the tool has all kinds of wonderful features that LINQ, SQL and Regular Expression programmers alike will want to use regularly long after they’ve read the book.” -Chris Sells, Connected Systems Program Manager, Microsoft   About the Author   Joseph Albahari is a core C# design architect at Egton Medical Information Systems, the largest primary healthcare software supplier in the UK. He has been developing large-scale enterprise applications on .NET and other platforms for more than 15 years, working in medical, telecommunication and education industries. Joseph specializes in writing custom components and controls, and has designed application component frameworks for three companies.   Ben Albahari is currently involved in the bioinformatics business. He was a Program Manager at Microsoft for 5 years, where he worked on several projects, including the .NET Compact Framework and ADO.NET.   He was the cofounder of Genamics, a provider of tools for C# and J++ programmers, as well as software for DNA and protein sequence analysis. He is a co-author of C# Essentials, the first C# book from O’Reilly, and of previous editions of C# in a Nutshell.
LINQ is the part of the .NET Framework that provides a generic approach to querying data from different data sources. It has quickly become the next must-have skill for .NET developers. Pro LINQ: Language Integrated Query in C# 2010 is all about code. Literally, this book starts with code and ends with code. Most books show the simplest examples of how to use a method, but they so rarely show how to use the more complex prototypes. This book is different. Demonstrating the overwhelming majority of LINQ operators and prototypes, it is a veritable treasury of LINQ examples. Rather than obscure the relevant LINQ principles in code examples by focusing on a demonstration application you have no interest in writing, this book cuts right to the chase of each LINQ operator, method, or class. However, where complexity is necessary to truly demonstrate an issue, the examples are right there in the thick of it. For example, code samples demonstrating how to handle concurrency conflicts actually create concurrency conflicts so you can step through the code and see them unfold. Face it, most technical books, while informative, are dull. LINQ need not be dull. Written with a sense of humor, this book will attempt to entertain you on your journey through the wonderland of LINQ and C# 2010. What you’ll learn How to query Databases with LINQ to SQL, write your own entity classes, and understand how to handle concurrency conflicts. * How to leverage all the new LINQ relevant C# 2008 language features including extension methods, lambda expressions, anonymous data types, and partial methods. * How to use LINQ to Objects to query in-memory data collections such as arrays, ArrayLists, and Lists to retrieve the data you want. * Why some queries are deferred, how a deferred query can bite you, and how you can make deferred queries work for you. * How to use LINQ to XML to revolutionize your creation, manipulation, and searching of XML data. * How to query DataSets with LINQ to DataSet so you can coexist with legacy code and use LINQ to query databases other than SQL Server. Who is this book for? Apress, 2010 This book is written for the proficient C# developer, but you do not need to be up on all the latest C# features to understand the material. When you finish this book, you will have a much greater understanding of the latest C# features. amazon link:http://www.amazon.com/exec/obidos/ASIN/1430226536/buythisbooks-20

8,497

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 LINQ
社区管理员
  • LINQ
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧