linq-to-entities

Linq: Dynamic Query Contruction: query moves to client-side

Hi all, I've been following with great interest the converstaion here: http://stackoverflow.com/questions/3769141/construct-query-with-linq-rather-than-sql-strings with regards to constructing expression trees where even the table name is dynamic. Toward that end, I've created a Extension method, addWhere, that looks like: static pub...

pagination in entity framerowk

What is the best practice for pagination in Entity framework? Should one hit database twice, one to get total record count and second to get the records? Thanks in advance. ...

linq to entities 3.5 across multiple databases in same engine

Hi, What do i need to do in order to be able to query across multiple databases which are in the same db engine? I have added the .edmx file of 1 database, but i only need 1 view from another db. Thanks in advance! ...

CompiledQuery with List.Contains (where...in list) functionality?

I'm attempting to write a CompiledQuery using Linq-to-Entities that will replace a stored procedure that takes two array (in this case, comma-delimited TEXT) parameters. Essentially, the SQL is be something like this: *Stored Proc definition* @ArrayParm1 TEXT, @ArrayParm2 TEXT -- etc. SELECT [fieldList] FROM someTable WHERE som...

Linq: Querying a "Virtual" columns created from one split column

Hi all, I'm working with a pretty nasty looking, but non-changable db. We've got a table, called "Locations" with column, "Position" This column has values like "A SHELF 5" Which means "Case A, Shelf 5". In an ideal world, I'd have a Case and Shelf column, with the values "A" and 5, respectively. What I'm wondering, is if there's a...

how to query this in linq

Hi i have this SQL SELECT * FROM [dbo].[LeftHand] left outer JOIN [dbo].[Head] ON [LeftHand].[ID] = [Head].[LeftHand_Id] WHERE [Head].[RightHand_Id] Not IN (59,60,63,64,65) or [Head].[RightHand_Id] is null [Head] */ \* / \ 1/ \1 [LeftHand] [RightHand] ([LeftHand may h...

help with linq to sql many to many query

Hi I have following entities A_Entity ----------- AId AB_Entity ----------- AId BId B_Entity ----------- BId I have a function that helps in building the query based on the input provided. In this case I have to build a query to fetch all A_Entities that have matching BId (provided as input to the function) public static IQueryabl...

Nested LINQ returning a this method cannot be translated into a store expression exception

The following LINQ: retval = ( from jm in entities.JobMasters where jm.UserId == userId && jm.IsRemote == false select new JobDto { JobMasterId = jm.JobMasterId, ExternalTaskId = jm.ExternalTaskId, JobDetails = ( from jd in ...

Optimize Linq code

Tables: Item Id Keyword Id Keyword ItemKeyword ItemId KeywordId SequenceNumber for searching items via keyword: Keyword keyword = Keyword.FirstOrDefault(a => a.Keyword .Equals(input, StringComparison.InvariantCultureIgnoreCase)); IEnumerable<Item> items = keyword.ItemKeyword.OrderBy(a => a.SequenceNumber) .SelectMany(a => a...

Linq-to-SQL or Linq-to-Entities with ASP.NET 3.5 and SQL Server 2005

I am starting a new project using C# and ASP.NET 3.5 with SQL Server 2005, and I am trying to decide which ORM is the best to use between LinqToSQL, LinqToEntities, or NHibernate. Ideally I would like to use the preferred Microsoft best practice; but I need to use a solution that will provide performance comparable to using stored proce...

Entity Data Model, Dynamic Linq, multiple table dynamic Where clause, strongly typed return types

Hello, When writing a method for an oData service I have the below linq, for which I need to have a dynamic "where" clause to filter the results (the "new"s in the joins are for composite PKs in the Entity Data Model): var query = from pl in CurrentDataSource.ProductListing join pla in CurrentDataSource.ProductListingAttri...

Killing Two Birds with One Stone in RIA Services with Silverlight

Here's the issue: The database is highly normalized, and one particular query relies on the multiple relationships in the database. The query is designed to join all the tables, construct the entire object, and then return a list of those objects. In other words this particular query does a lot of work. Now, the query does only return...

Sorting and paging compiled queries

Is it possible to compile queries which will be used with paging and sorting? For example does this make sense: this.query = CompiledQuery.Compile<...>( .. from row in dbx.Table select row ) .. var select = this.query.OrderBy(..).Skip(..).Take(..); Is this plausible? Or will it recompile every time Order, Skip, Take parameters chang...

Is this LINQ statment vulnerable to SQL injection?

Is this LINQ statment vulnerable to SQL injection? var result = from b in context.tests where b.id == inputTextBox.Text select b; where context is an Entity and tests is a table. I'm trying to learn LINQ and I thought that the benefit of it was that it wasn't vulnerable to sql injection, but some stuff I've see has said differ...

Help With Generic LINQ OrderBy Lambda Expression

Hi Guys, Trying to get an OrderBy on an IQueryable to work, not having much luck. Here's my method: public ICollection<T> FindAll<T>(Expression<Func<T,bool>> predicate, Expression<Func<T,int>> orderingKey) where T : Post { return repository .Find() .Where(predicate) .OfType<T>() ...

Can you apply OOP to Linq Projections?

Using Visual Studio 2010 .Net Framework 4 C# Linq to Entities Issue I would like to be able to apply Object Oriented Principles like DRY and SOLID to some Linq Projections. With compiled queries or passed parameters I can apply these to the rest of Linq successfully so far, just not in the projections. Please let me know if this i...

Linq to Entity Framework (v1)

Hi - I'm currently working on a solution, where there are the concepts of users, work queues and work items. At a basic level a user has a series of work queues assigned to them, the work queue containing the work that is to be done. So - at the moment we have a basic Linq query that returns all of the queues, but I was hoping to res...

How to produce many agregations over the set of rows

I'm having difficuly mapping a simple T-SQL query such as this select min(price) as MinPrice, max(price) as MaxPrice, avg(price) as AvgPrice from titles to a Linq Expression such as this: var answer = from t in Titles select new { MinPrice=Min(t.Price), MaxPrice=Max(t.Price), AvgPrice=Avg(t.Price)}; Obviously this doesn't work sinc...

Inform LINQ that a string represents a decimal and not a double value?

I am using the following snippet: var ws = string.Format(" it.{0} >= {1} && it.{0} <= {2} ", column, min, max) as part of query. “it” represents the record at hand. I then use this string in a Var result = AllRecords .Where(ws) .OrderBy(it.ProductName); The problem I have, is that when the column type is Decimal the...

linq to entities case sensitive comparison

This isn't a case-sensitive comparison in Linq to entities: Thingies.First(t => t.Name == "ThingamaBob"); How can I achieve case sensitive comparison with Linq to entities? ...