linq-to-entities

Doing Eager Loading and Projection in Linq to Entities

This is a spin off from another question I posted a few days ago that was successfully answered but it really didn't get into the underlying issue I was having but wasn't able to express fully in my original query. I have a table Product. Product is related to ProductDescription in a one-to-many relationship. ProductDescription can have...

Invoke an Expression in a Select statement - LINQ to Entity Framework

I'm trying to use an already existing Expression building class that I made when trying to do a select clause, but I'm not sure how to attach the expression to the expression tree for the Select, I tried doing the following: var catalogs = matchingCatalogs.Select(c => new { c.CatalogID, ...

Get the second highest salary of the employees using LINQ

I have the following entity public class Employee { public int EmployeeID { get; set; } public string EmployeeName { get; set; } public string Department { get; set; } public long Salary { get; set; } } I am trying to find out the second highest salary for the employees of every individual department using LINQ. So fa...

LINQ to Entities produces query containing datetime2 on SQL 2005 Express

I've got a LINQ to Entities app and a database project to manage the schema in a VS 2010 solution targetting .NET 4.0. The entity model is currently reverse engineered from the database. One of the tables is defined with a column of type datetime. The database project is configured to use SQL Server 2005 compatability mode and so it all ...

LINQ to entities - left join with condition

I have a table GameVersion with FK (allowing nulls) to Game table. When I do this: GameVersion[] q = (from gv in db.GameVersion.Include("Game") select gv).ToArray(); It works OK, while iterating GameVersion objects I can see null references to Game in some records (just like on the databse), so it works like...

MySql, Entity Framework, Inner Joins with null checks generated

Hi, I have had a play with the Entity Framework and the MySQL driver. Excuse me if this is a silly question. Table adverts has a FK to the PK of vacancies. Both fields are marked as NOT NULL. I am performing a simple join: var qry = (from vacancy in context.vacancies join advert in context.adverts on vacancy...

LINQ to Entities - limiting included tables

Using two tables with a one to many relationship (such as Make -> Model), how do I return a Make with limited Model children in an IQueryable function? When I pass in “camry” as a variable, I want to get back a Toyota Make with only children called “camry”, not all children. Basically, I want to recreate this SQL statement: SELECT ...

Entity Framework Calculated Property problem

I've an Entity Framework model (v.1.0) that I'm trying to extends with a calculated property. I've created the partial class to extend the entity object "Offer" in this way: namespace MyModelNamespace { public partial class Offer { public bool MyProperty { get { // my stu...

Does Linq to Entities Include work across calls?

If I have something like this: x = from f in first.Include("second") where f.id == 1 select f y = from s in second where s.first.id == 1 select s Will two queries be sent to my database? I realize that I could just set y = f.second to ensure that only one call is made, but I frequently want to factor my code such that...

Dynami table names with Linq to entities?

Hello Wondered if there is a way to provide table name for linq query at runtime. I am interested in simple quert like "select * from @someTableName". I've searched a lot for the answer but couldnt find any help on the net. There was a post on stackOverflow --> link Dave Russel suggested to do: "var p = ctx.GetType.GetProperty(oNam...

How do you re-use select statements with Entity Framework?

Given the following query: var query = from item in context.Users // Users if of type TblUser select new User() // User is the domain class model { ID = item.Username, Username = item.Username }; How can I re-use the select part of the statement in other quer...

Retrieving a related table as a List<POCO> using Entities

I'm having a problem when I attempt to create a generic List using a POCO within a LINQ query that creates another POCO: var user = from u in ctx.users select new User { id = u.UserID, name = u.Name, roles = u.Roles.ToList() }; I have created both a User and Role class. If I define 'roles' in User as: public List<Roles> r...

Tables in LINQ to Entities are not related

I'm working with asp.net 3.5 WebForms and LINQ to Entities. I created the database with their relationships, but when I go to import the data with LinqToEntities, some reports and have not seen any reports 1 to 1. Can anyone help me? I can create them after the reports have imported the tables LinqToEntities? ...

Error - SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

i have an app written for 2008. We are using linq to entities. We've now had to switch the DB to 2005. I am getting the following error on linq SELECT queries: Error - SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM. The offending line is: DateOfBirth = ((s.Date_Of_Birth == null) || (s.Date...

Is it possible to build an ObjectQuery<T> from an Expression created by another IQueryable<T>?

I'd like to pass around a custom IQueryable object to repository methods. Example: // a fake query to generate an expression public class MockQuery<T> : IOrderedQueryable<T> { // implement my own query provider internally } public class EFRepository : IRepository<MyType> { public IList<MyType> ExecuteQuery(IQueryable<MyType> ...

Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Collections.Generic.IList'

I have method : public DzieckoAndOpiekunCollection GetChildAndOpiekunByFirstnameLastname(string firstname, string lastname) { DataTransfer.ChargeInSchoolEntities db = new DataTransfer.ChargeInSchoolEntities(); DzieckoAndOpiekunCollection result = new DzieckoAndOpiekunCollection(); if (firstname == nul...

LINQ to Entity RIA Query syntax?

I am using RIA services with Entity Framework- I have the following sql select statement: select * from TaskTable t, MapTable mt where mt.SiteID=1 and t.EndPointID=mt.EndPointID How do I write this using method queries and lamda, or any other way I can use in my domain services? All the examples I see return a new object- do I really ...

Has Microsoft confirmed their stance on LINQ to SQL end-of-life?

I'm trying to make an educated decision about what ORM to use for a number of legacy applications I'm responsible for porting to MVC 2. The ORMs I've looked at are LINQ to SQL, LINQ to Entities and nHibernate. L2S seemed to be the easiest, but I've found numerous articles and blog entries stating that Microsoft would no longer be updatin...

How make LINQ query with GroupBy and LEFT JOIN

I'm using EF4 and i need to make this query with LINQ but i don't know how. If i have 3 tables: ProductType Product Season ProductType -> one-to-many -> Product -> many-to-one -> Season i would like to have a list of all the ProductType with their Products for one Season. Please note that i need to list ALL the ProductType even if ...

Linq to Entities 4.0 - Optimized Query and multiple calls to database in a single query

Hi, Can anyone tell me if the following query calls the database multiple times or just once? var bizItems = new { items = ( from bl in db.rc_BusinessLocations orderby bl.rc_BusinessProfiles.BusinessName select new BusinessLocationItem { BusinessLocation = bl, BusinessProfile ...