LinqToObject和LinqToSql的区别

以下不难看出IQueryable继承自IEnumerable 但是二者却有着本质的区别

复制代码
//
// 摘要:
// 提供针对特定数据源(其中数据类型未未知)评估查询的功能。
//
// 类型参数:
// T:
// 数据源中数据的类型。
public interface IQueryable : IEnumerable, IEnumerable, IQueryable
{
}
复制代码
这是IQueryable一些实现 包含表达式目录树Expression参数并内置委托

复制代码
//
// 摘要:
// Filters a sequence of values based on a predicate. Each element’s index is used
// in the logic of the predicate function.
//
// 参数:
// source:
// An System.Linq.IQueryable1 to filter. // // predicate: // A function to test each element for a condition; the second parameter of the // function represents the index of the element in the source sequence. // // 类型参数: // TSource: // The type of the elements of source. // // 返回结果: // An System.Linq.IQueryable1 that contains elements from the input sequence that
// satisfy the condition specified by predicate.
//
// 异常:
// T:System.ArgumentNullException:
// source or predicate is null.
public static IQueryable Where(this IQueryable source, Expression<Func<TSource, int, bool>> predicate);
复制代码
这是IEnumerable类型一些实现 并不是表达式目录树仅仅是一个委托来实现

复制代码
1 //
2 // 摘要:
3 // Filters a sequence of values based on a predicate. Each element’s index is used
4 // in the logic of the predicate function.
5 //
6 // 参数:
7 // source:
8 // An System.Collections.Generic.IEnumerable1 to filter. 9 // 10 // predicate: 11 // A function to test each source element for a condition; the second parameter 12 // of the function represents the index of the source element. 13 // 14 // 类型参数: 15 // TSource: 16 // The type of the elements of source. 17 // 18 // 返回结果: 19 // An System.Collections.Generic.IEnumerable1 that contains elements from the input
20 // sequence that satisfy the condition.
21 //
22 // 异常:
23 // T:System.ArgumentNullException:
24 // source or predicate is null.
25 public static IEnumerable Where(this IEnumerable source, Func<TSource, int, bool> predicate);
USB Microphone https://www.soft-voice.com/
Wooden Speakers https://www.zeshuiplatform.com/
亚马逊测评 www.yisuping.cn
深圳网站建设www.sz886.com

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
LINQ to SQL 是一种使用 C# 语言中的 LINQ(语言集成查询)功能来访问关系数据库的技术。通过 LINQ to SQL,您可以使用 LINQ 查询语句来查询和操作数据库中的数据。LINQ to SQL 还提供了一种方便的方式来映射数据库表格到 C# 中的类对象,使得您可以使用面向对象的方式来处理数据库中的数据。 在使用 LINQ to SQL 时,您需要先创建一个 DataContext 对象,该对象表示与数据库的连接。然后,您可以使用 LINQ 查询语句来查询和操作数据库中的数据。例如,以下代码演示如何查询一个名为 "Customers" 的表格中所有客户的信息: ```csharp using System.Linq; // 创建 DataContext 对象 DataClasses1DataContext db = new DataClasses1DataContext(); // 查询所有客户信息 var customers = from c in db.Customers select c; // 遍历查询结果 foreach (var customer in customers) { Console.WriteLine("Customer: {0} {1}", customer.FirstName, customer.LastName); } ``` 此外,您还可以使用 LINQ to SQL 来执行插入、更新和删除等数据库操作。例如,以下代码演示如何向 "Customers" 表格中插入一条新的客户记录: ```csharp // 创建新的客户对象 Customer newCustomer = new Customer { FirstName = "John", LastName = "Doe", Email = "[email protected]" }; // 将新客户对象添加到 DataContext 中 db.Customers.InsertOnSubmit(newCustomer); // 提交更改到数据库 db.SubmitChanges(); ``` 以上代码中,InsertOnSubmit() 方法将新客户对象添加到 DataContext 中,而 SubmitChanges() 方法将更改提交到数据库。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值