linq-to-entities

linq count with join on multiple tables

Let's say I have 3 tables: carts, baskets and eggs where a basket can contain many eggs and where carts contain many baskets. Each basket has a foreign key that maps to a cart and each egg has a foreign key that maps to a basket. I need to return a table that contains these columns: -Cart Name -Number of Baskets in Cart -Number of Eggs...

How to pass viewmodel to controller?

Hello, I've a problem with my viewmodel. I've a DropDownList with many translationvalues (pattern here) In My controller - HTTPGET : public ActionResult Edit(int id) { int DropDownListValueId = id; SelectListViewModel viewmodel = new SelectListViewModel(0, DropDownListValueId); return...

Do Linq to Entities queries *always* hit the database?

My understanding of the Entity Framework is that if it can answer a query from its cache, it will. My simple testing, however, shows repeated queries hit the database even though they were previously answered positively: var u1 = context.Users.SingleOrDefault(u => u.Id == 1); var u2 = context.Users.SingleOrDefault(u => u.Id == 1); Th...

Many to many ordered by count of relationship (Entity Framework, Linq)

i have a table structure like this... When I import this into entity framework it looks like this... What I need to do is build a query from LINQ that will return a list of every unique store, populated with a list of people who like that store. (easy, right?) THE CATCH: I need to filter the list to the person's list of friends th...

Linq to entities - how to select entities with a where condition on their entitycollection ?

Hi all, I found several times people asking for the same question but it seems that the answer was never satisfying altough it should be pretty easy (in theory). Here is my question : I have an entity called "Company" inside which I have an entityCollection "Employees" (one to many). I need to retrieve all Companies and for each of the...

LINQ to EF - Why is this query pulling back all the data THEN counting?

Using EF 3.5 - why does the first query appear to generate a SELECT COUNT(*)... whilst the second appears to pull back all the data before performing the where? var model = new SageEntities(); Func<nltranm, bool> marked_as_extracted = n => n.history_ref != null; // SELECT COUNT(*) ? var reco...

How to rewrite sql query below to linq to entity query?

SELECT COUNT(*) FROM dbo.Table WITH (NOLOCK) WHERE Columnn1 IN (1,2) AND Column2 IN (SELECT id FROM dbo.Table2 WHERE id2 = 5 AND id3 = 1) AND id4 = 8 ...

How can I execute an Oracle function from within a LINQ expression in Entity Framework 4?

I am using Visual Studio 2010, C#, Entity Framework 4 and Oracle 10g. I need to be able to return the result of a database function as a scalar property of an anonymous type. My Oracle schema has two tables, PARENT and CHILD, and a function FNC_ADD. I have created an entity model using the Visual Studio ADO.NET Entity Data Model templ...

Dynamic predicate with Entity Framework

Hi, I am trying to build a dynamic predicate with Entity Framework by mapping an enum to the column field: In the where clause i have entered ?? as i am not sure what to put there, i want this be dynamic like in this article, although that doesn't work me in EF on;y linq to sql: http://stackoverflow.com/questions/2497303/how-to-specif...

LINQ Select Distinct while ignoring the XML field

Hello, I have a complex LINQ query (using LINQ 2 EF) that can return duplicate results and I'm thus using the .Distinct() method to avoid duplicates. Here's the skeleton: var subQuery1 = // one query... var subQuery2 = // another query... var result = subQuery1.Distinct().Union( subQuery2.Distinct() ).ToArray(); Each of the sub que...

Best practice for populating a model object

Suppose I have few model classes like Person.cs, Car.cs, Manufacturer.cs each of which has 30-40 properties of varying datatypes. These models have to be populated using a Linq based framework called 'XrmContext' based on a Guid (primary key) match. Ordinary way of doing this to populated each column one by one manually like Person m...

Linq2Entities Include with Take - load issue

Note: I know there are a number of questions around for issues with Linq's .Include(table) not loading data, I believe I have exhausted the options people have listed, and still had problems. I have a large Linq2Entities query on an application I'm maintaining. The query is built up as such: IQueryable<Results> query = context.MyTable ...

LINQ to Entities, several one-to-one references to the same tables and naming

Hi, I've started porting a .NET SQL Server application to LINQ to Entities. I have (among others...) one table called Users, and one called Time. Time is reported on a specific user (UserId), but it is also recorded which user made the report (InsertedByUserId) and possibly who has updated the Time since insert (UpdatedByUserId). This g...

What is the difference between these two LINQ queries?

Looking at the profiler I see a few differences. The second query which uses the include will in fact return data from related to the secondary table CountryCodes. This part makes sense to me. I don't however understand why this query has two joins. First it does a regular inner join between CountryCodes ands CountyCodeTypes (on the ...

LINQ to Entities - how to persists column order?

Within LINQ to Entities entity model (supported by .edmx file) sometimes column order changes within the tables. It may happen after you’ve edited the table structure (added or deleted columns, renamed them, etc.). As a result an automatically generated Create method changes and existing code becomes broken. Example: You have entity ca...

Should I switch from Web Services to Entities to do my SQL data manipulation?

I have a number of web application projects in a .net environment that use web services created by my DBA to select, update, and delete data from my SQL database. My DBA suggests that he will continue to create new web service interfaces for new projects in the future. I understand that this process is somewhat inefficient in terms of ...

Linq-to-Entities: LEFT OUTER JOIN with WHERE clause and projection

I'm having a heckuva time figuring out how to translate a simple SQL LEFT OUTER JOIN with a two condition where clause into a working Linq-to-Entities query. There are only two tables. I need values for all rows from Table1, regardless of matches in Table2, but the WHERE clause uses fields from Table2. In SQL, the two parameters would...

LINQ to Entity problem. Self-referencing entity.

Hello! I have a Self-referencing entity (0 to *). When i tried to delete one, got an error. The structure of data is: servise1 --service 1.1 --service 1.2 ---service 1.2.1 ---service 1.2.2 ---service 1.2.3 --service 1.3 --service 1.4 service 2 and so on... I just need to delete one of the services with all subservices (cascade). Ple...

Entity Framework How to query data in a Navigation property table

I have a the following setup m_handsets = From p In RL.App.TComEntities.tblTelephoneNumbers _ Where p.companyId = m_CompanyID _ Select p m_handsets = DirectCast(m_handsets, ObjectQuery(Of RL.TelephoneNumbers)).Include("tblCalls") where m_ha...

Create a method that will return a Lambda Expression that will be use in a lambda WHERE clause. Got error 1025.

I use Framework Entity 4 in my project. I would like to create a function that will return an Expression Nothing seem to work. I get this Internal .Net Framework Data Provider error 1025. Here is my Expression Method public Expression<Func<SupplierTypeText, bool>> GetLmbLang() { return (p => p.LangID == 1); } I call...