linq-to-entities

LINQ or Entity Framework creates unbounded SQL statement.

I work on speed optimization of my application, and what I have found is that LINQ (or EF) is creating some strange SQL for me that works slow. Here is some code : SomeList.AddRange(_databaseView .Select(l=> new SomeViewModel { Date = l.Date, ...

Entity Framework: how to do correct "Include" on custom type

Suppose we have 2 types, mapped to a Database via EF 4. Schedule 1.....1 Visit Also, we have third custom view type public class ScheduleView { public Schedule Schedule { get; set; } public Visit Visit { get; set; } } So we can write the join query var query = Context.Schedule.Join(Context.Visit ,/*Schedule join key defin...

Update existing EntityCollection in Entity Framework

I try to work with link to entity, and i want to work directly with my entity in my application. using System; using System.Collections.Generic; using System.Linq; using System.Text; using Calandar.Business.Manager.Data; namespace Calandar.Business.Models.Args { public class SaveExpertArgs { public ExpertEntity Expert {...

Dynamic tables from a stored procedure using Linq to Entities

Hi, I have a question about Entity Framework and Linq to Entities. My .NET version is 4.0. I'm refactoring the database access layer of an existing application, and I plan to use Linq to Entities (instead of today's DataReaders and SQL strings). The structure of the database cannot be altered. My problem comes from a stored procedure, ...

Linq to Entities: NullReferenceException on a simple select

I have the following sentence: var customers = from customer in Context.ps_customer select customer; As you can see, it is the most simple sentence in the world. Well, it throws a NullReferenceException, and I don't have any idea why. in fact, the exception is thrown at List<ps_customer> clientes = customers.ToList<p...

DataSource.Table.Where(stringOfConstraint) does not exist in LinqToSQL for OData support?

I'm looking at this Telerik demo, and am unable to get the "count" statement to work. I believe that the following command is only supported on EntityFramework, and not Linq2SQL. return CurrentDataSource.Products.Where(where).Count(); The parameter "where" in lowercase is actually a string that is passed in the ADO.Net DataServices ...

Entity framework, check duplicates ignoring case

Hi, I want to check for duplicates in Entity Framework using Linq-To-Entities, ignoring cases. What's the best way to do it? As far as I'm aware, context.[Entity].Contains(item, IEqualityComparer) method is not supported. Do I have to do ToList() which reads the entire table into memory just to check it? Thanks, ...

How to pass a C# Select () extension delegate or expression to a Repository?

Everyone projects once in a while: var c = dc.Products.Select( p => new {p.id, p.name}); // results in c having properties of .id and .name What if I want to refactor that in to a method. How would I pass the Select parameter? var c = myFunction( p => new {p.id, p.name}); Product myFunction( ??? myLambda) { var c = dc.Product...

IQueryable Lambda Projection Syntax

I have an IQueryable whose Entity Framework 4 objects I would like to project to their DTO equivalents. One such object 'Person' is an EF4 class, and the corresponding POCO PersonP is a class I've defined. I am using Automapper to map between them. However, when I try the following code: IQueryable<Person> originalModel = _repo.QueryAll...

Linq, simple filter error...C#

Hi, Using linq and silverlight got this error....I am using POCO....DTO = POCO public IEnumerable..... var query = from d in Context.Documentos where d.CodigoEquipamento == documentoDTO.CodigoEquipamento && d.Codigo == tipoEquipamentoDTO.Codigo select new DocumentoDTO { ...

EF4 error:The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects.

hi I have a question I'am using for my web site wscf in vs2010 that use de model MVP(model,view,presenter) and for my model layer (data acces layer) iam using EF so I have this model http://yfrog.com/mymodelyj that seguimiento's tables is an intermediate table between be cliente and gventa tables so I have my Insert in seguimiento's ta...

EF Where(x => x.ColumnVal == 1) vs FirstOrDefault(x => x.Column == 1)

I had a LINQ query that loads a hierarchy of objects like the following. Query #1 var result = db.Orders .Include("Customer") // many other .Include() here .FirstOrDefault(x => x.Customer.CustomerId == 1 && x.OrderId == orderId); I was having MAJOR perfo...

Select Anonymous type with Dynamic Expression API

I'm using Dynamic Expression API (System.Linq.Dynamic) with Linq to Entities. My linq statement is below. var query = this.db.Products.AsQueryable() .Where(strCondition) .OrderBy("ProductNumber") .Select("new(ProductNumber, ProductDescription, ProductCategory.Name)"); Now that I have the "query", I do...

EF4 POCO, how i can filterByXX?

I am using this query: public IEnumerable.....{ var query = from d in Context.Documentos where d.CodigoEquipamento == documentoDTO.CodigoEquipamento && d.Codigo == tipoEquipamentoDTO.Codigo select new DocumentoDTO { Codigo = d.Codigo, CodigoEquipamento = d.CodigoEqu...

How to represent this SQL query in LINQ to entities?

Hello I'm kind of new to LINQ and I'm trying to represent the following query in LINQ to Entities: Select * from Cotations CT1 where CT1.CotationID = iCot_ID and Revision = (select max(revision) from Cotations CT2 where CT1.CotationID = CT2.Cotation) where iCot_ID is an external parameter, and...

Entity Framework 4: How to turn a string into an object for .OrderBy(p => p.fieldname)?

Now this is a trick question because you cannot do this: var a = myDB.Where(p => p.field == "filter").OrderBy("it." + fieldname); You could change the Where to accept a string, which allows you to change the OrderBy to accept a string, but that's not the question. How can you turn a string like "productID, productName" in to an Order...

get duplicates from a table using linq to entities

In my database i got a column named hashcode. this column stores the hashcodes of pictures. I want to run a query that searches for duplicate hashcodes using linq to entities. I got stuck with the 'where clause'. How do i compare hashcodes? var ans = this.pe.TPicture.Where(p => this.pe.TPicture.Count(x => x.Equals(p)) > 1); ...

Linq to Entities - Query errors in Web but not Unit tests

Hello, I have a query that errors out when I use it in a MVC 2.0 project, but not when I run unit tests against it (works fine). Below is the query, "User" is an entity. The error I get shows up on the Known issues to consider for EF (http://msdn.microsoft.com/en-us/library/bb896317.aspx) but it seems pretty basic this should work, an...