`
wangdeshui
  • 浏览: 246972 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Linq to SQL Dynamic 动态查询

阅读更多

在开发中我们常需要使用动态的条件来组合查询,scotte博客里提到了MS提供的一个动态查询类库Basic Dynamic LINQ C# Sample,这个可以给我们提供不少方便,但是给的示例实在太简单,实际当中我们很多不能像他这样用。

image

首先引入DynamicLibrary.cs,下面是我使用过程中的一些运行正确的用法(里面使用返回DataSet是因为对旧程序升级),我觉得写法很怪异,但是的确这样是正确的。

image

调用

image

最终生成的SQL语句

 

SELECT COUNT(*AS [value]
FROM [dbo].[News] AS [t0]
WHERE ([t0].[NewsIsDeleted] IS NULLAND ([t0].[NewsIsDisplay] = 1)
AND
 ([t0].[Newslanguages] = @p0AND ([t0].[NewsIsHome] = 1AND ([t0].[NewsIsTop] = 1)
-- @p0: Input NVarChar (Size = 8; Prec = 0; Scale = 0) [engbtest]
--
 Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.21022.8 

 

另外分享一个query to datareader的方法,有了datareader可以生成datatable,dataset等:

image

注:不知各位有没有更好的办法?

分享到:
评论

相关推荐

    LINQ_to_SQL语法及实例大全

    LINQ to SQL语句(23)之动态查询 90 1.Select 91 2.Where 92 LINQ to SQL语句(24)之视图 94 LINQ to SQL语句(25)之继承 96 1.一般形式 97 2.OfType形式 98 3.IS形式 98 4.AS形式 99 5.Cast形式 99 6.UseAsDefault形式...

    WPF Data Binding with LINQ to SQL

    This is the final part of a three-part series on using LINQ to SQL: Part 1: Mapping Tables to Objects Part 2: Adding/Updating/Deleting Data Part 3: WPF Data Binding with LINQ to SQL These tutorials ...

    Linq TO Sql 扩展方法

    Linq TO Sql 扩展方法,方便Linq TO Sql的深入学习,里面包含多个扩展文件

    LINQ to Objects Using C# 4.0: Using and Extending LINQ to Objects and Parallel LINQ

    Using LINQ to Objects, .NET developers can write queries over object collections with the same deep functionality that was once available only with SQL and relational databases. Now, for the first ...

    c# Linq WebService rss

    •SampleQueries: 这是最重要的示例,其中包含了 500 多个关于如何在 LINQ to Objects、LINQ to SQL、LINQ to XML 和 LINQ to DataSet 中使用各个查询运算符的例子。 •SimpleLambdas: 几个关于如何编写和使用 ...

    LINQ TO OBJECTS USING C# 4.0

    Using LINQ to Objects, .NET developers can write queries over object collections with the same deep functionality that was once available only with SQL and relational databases. Now, for the first ...

    System.Linq.Dynamic.Core:来自System Linq Dynamic功能的.NET Standard .NET Core版本

    总览使用此库,可以在IQueryable上编写动态LINQ查询(基于字符串): var query = db . Customers . Where ( " City == @0 and Orders.Count >= @1 " , " London " , 10 ) . OrderBy ( " CompanyName " ) . Select ...

    Dynamic Linq Framework-开源

    在C#3.0中针对SQL数据库动态创建Linq查询的框架,该数据库自动填充用于WPF绑定的ObservableCollection还包括Observable EntitySet 包装器,用于将EntitySet绑定到WPF控件ItemsSource

    VS2008中动态数据(Dynamic Data)示例 VS2008中动态数据(Dynamic.rar

    它通过在 runtime 自动发现 linq to sql 或 entity framework 数据模型,并确定如何从数据模型中呈现 UI,来实现此目的 包括:  ADO.NET Entity Framework  ADO.NET Data Services  Dynamic Data  动态...

    VS2008中动态数据(DynamicData)示例

    它通过在 runtime 自动发现 linq to sql 或 entity framework 数据模型,并确定如何从数据模型中呈现 UI,来实现此目的 包括: ADO.NET Entity Framework ADO.NET Data Services Dynamic Data 动态数据的Demo

    c# 4.0 in nutshell 4th edition

    code contracts, dynamic programming, security, and COM interoperability. You'll also find updated information on LINQ, including examples that work with both LINQ to SQL and Entity Framework....

    Professional C# 4 and .NET 4

    dynamic objects in C#, named and optional parameters, COM specific interop features, and type-safe variance Helps you master topics such as Language Integrated Query (LINQ), LINQ to SQL, LINQ to XML,...

    Modern Data Access with Entity Framework Core

    Dynamic LINQ, SQL, Stored Procedures, and Table Valued Functions- to using third-party products such as LINQPad, Entity Developer, Entity Framework Profiler, EFPlus, and AutoMapper. You’ll also ...

    Professional ASP.NET 3.5 SP1 Edition: In C# and VB(part1)

    How to work with data from enterprise databases including SQL Server® * Ways to debug, package, and deploy ASP.NET applications, monitor their health and performance, and handle errors * How ...

    StackExchange开源.Net ORM框架 Dapper.NET.zip

    Linq 2 SQL ExecuteQuery 181ms Entity framework ExecuteStoreQuery 631ms Performance of SELECT mapping over 500 iterations - dynamic serialization Method Duration...

    C# List实现行转列的通用方案

    System.Linq.Dynamic其它用法 总结 问题介绍 以家庭月度费用为例,可以在[Name,Area,Month]三个维度上随意组合进行分组,三个维度中选择一个做为列显示。 /// /// 家庭费用情况 /// public class House { ...

Global site tag (gtag.js) - Google Analytics