问题标签 [linq-to-entities]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
14919 浏览

.net - Expression.Invoke 在实体框架中?

实体框架不支持Expression.Invoke运算符。尝试使用它时收到以下异常:

“LINQ to Entities 不支持 LINQ 表达式节点类型‘Invoke’。

有没有人为这个缺失的功能找到解决方法?我想在实体框架上下文中使用此处详述的 PredicateBuilder。

编辑 1 @marxidad - 我喜欢你的建议,但它确实让我有些困惑。您能否就您提出的解决方案提供进一步的建议?

编辑 2 @marxidad - 感谢您的澄清。

0 投票
9 回答
21852 浏览

linq - Learning about LINQ

Overview

One of the things I've asked a lot about on this site is LINQ. The questions I've asked have been wide and varied and often don't have much context behind them. So in an attempt to consolidate the knowledge I've acquired on Linq I'm posting this question with a view to maintaining and updating it with additional information as I continue to learn about LINQ.

I also hope that it will prove to be a useful resource for other people wanting to learn about LINQ.

What is LINQ?

From MSDN:

The LINQ Project is a codename for a set of extensions to the .NET Framework that encompass language-integrated query, set, and transform operations. It extends C# and Visual Basic with native language syntax for queries and provides class libraries to take advantage of these capabilities.

What this means is that LINQ provides a standard way to query a variety of datasources using a common syntax.

What flavours of LINQ are there?

Currently there are a few different LINQ providers provided by Microsoft:

There are quite a few others, many of which are listed here.

What are the benefits?

  • Standardized way to query multiple datasources
  • Compile time safety of queries
  • Optimized way to perform set based operations on in memory objects
  • Ability to debug queries

So what can I do with LINQ?

Chook provides a way to output CSV files
Jeff shows how to remove duplicates from an array
Bob gets a distinct ordered list from a datatable
Marxidad shows how to sort an array
Dana gets help implementing a Quick Sort Using Linq

Where to start?

A summary of links from GateKiller's question are below:
Scott Guthrie provides an intro to Linq on his blog
An overview of LINQ on MSDN

ChrisAnnODell suggests checking out:

What do I need to use LINQ?

Linq is currently available in VB.Net 9.0 and C# 3.0 so you'll need Visual Studio 2008 or greater to get the full benefits. (You could always write your code in notepad and compile using MSBuild)

There is also a tool called LinqBridge which will allow you to run Linq like queries in C# 2.0.

Tips and tricks using LINQ

This question has some tricky ways to use LINQ

0 投票
6 回答
12093 浏览

entity-framework - Linq to Entities 与 ESQL 的性能对比

使用实体框架时,ESQL 的性能是否优于 Linq to Entities?

我更喜欢使用 Linq to Entities(主要是因为强类型检查),但我的一些其他团队成员将性能作为使用 ESQL 的理由。我想全面了解使用这两种方法的利弊。

0 投票
2 回答
1323 浏览

.net - 如何使用 LinqToEntities 实现存储库模式?

如何使用 LinqToEntities 实现存储库模式 如何实现接口

0 投票
6 回答
1728 浏览

linq-to-entities - 为什么所有 Linq To 实体都讨厌?

我注意到似乎对 Linq To Entities 有相当多的敌意,尤其是来自 Alt.Net 的人。我理解对更多“拖放”编程的阻力,但据我了解,Linq To Entities 不需要它。

我们目前正在使用Linq to SQL,并且我们正在使用DBML文档来定义它(一旦你得到十几个左右的表,设计器就很没用了。)

那么为什么同样的方法对 Linq To Entities 不起作用呢?

0 投票
2 回答
3651 浏览

oracle - 如何使用实体框架实现数据库独立性

我已经使用实体框架启动了一个相当简单的示例项目。在该项目中,我从 SQL Server 2000 数据库创建了一个新的实体数据模型。我能够使用 LINQ to Entities 查询数据并在屏幕上显示值。

我有一个架构极其相似的 Oracle 数据库(我试图准确,但我不知道 Oracle 的所有细节)。我希望我的项目能够轻松地在 SQL Server 和 Oracle 数据存储上运行。我希望我可以简单地更改我的实体数据模型的配置字符串,而实体框架会处理剩下的事情。但是,它似乎不会像我想的那样无缝地工作。

有人做过我想做的事吗?同样,我正在尝试编写一个应用程序,该应用程序可以使用 Entity Framework 以最小的努力从 SQL Server 或 Oracle 数据库中查询(和更新)数据。第二个目标是在数据存储之间来回切换时不必重新编译应用程序。如果我必须“从数据库更新模型”可能没问题,因为我不必重新编译,但我不想走这条路。有谁知道可能需要的任何步骤?

0 投票
7 回答
54147 浏览

join - Linq to Entity 具有多个左外连接

我试图了解 LINQ to Entity 中的左外连接。例如,我有以下 3 个表:

公司、公司产品、产品

CompanyProduct 链接到其两个父表 Company 和 Product。

无论给定产品的 CompanyProduct 是否存在,我都想返回所有 Company 记录和关联的 CompanyProduct。在 Transact SQL 中,我将使用左外连接从 Company 表中走出来,如下所示:

我的数据库有 3 家公司,2 条 CompanyProduct 记录与 ProductID 14 相关联。因此,SQL 查询的结果是预期的 3 行,其中 2 行连接到 CompanyProduct 和 Product,1 行仅包含 Company 表和空值在 CompanyProduct 和 Product 表中。

那么如何在 LINQ to Entity 中编写相同类型的连接来获得类似的结果呢?

我尝试了一些不同的方法,但无法正确使用语法。

谢谢。

0 投票
7 回答
21389 浏览

linq - 如何在 LINQ-to-Entities 3.5 中执行“值在哪里”

有人知道如何使用 LINQ-to-Entities 应用“值中的位置”类型条件吗?我尝试了以下方法,但它不起作用:

我相信这在 LINQ-to-SQL 中有效吗?有什么想法吗?

0 投票
4 回答
8222 浏览

linq-to-entities - LINQ-to-Entities(不是 Linq-to-SQL)中是否有 DataContext?

我最近问了一个关于跟踪 Linq-to-Entities的问题

我认为其中一个答案是不正确的,因为它们指的是使用 DataContext。是否有 LINQ-to-Entities 的 DataContext?如果是这样,我该如何得到它?

0 投票
1 回答
2698 浏览

linq-to-entities - 有人使用 lucene.net 和 Linq-to-Entities 吗?

如果有人这样做,请告诉我。我对lucene.net一无所知。我从未使用过它,但我听说过它。我想知道这样的东西如何与 Linq 实体框架集成?