linq-to-entities

Linq with EF dynamic search

I am using EF 3.5 with MVC. I want to made a search page, has some fields for criteria like date, int etc. What is the way in linq to entities to filter the result dynamically. If there are one parameter we can use .where(a=>a.id==1) but many combination with optional param how can i load results and then pass to model. ...

How do i convert this linq code to inline sql

How would I covert this query to inline sql or a stored procedure? var a = from arow in context.post where arow.post_id == id && arow.post_isdeleted == false select new { arow.post_id, PostComments = from c in context.comment where c.CommentPostID == arow.post_id select new ...

Entity Framework - DateTime in the where clause

I'm trying to convert this code from a stored procedure into a "LINQ to Entities" query: select * from myTable where venue_date + start_time <= @EndDate and dateadd(minute, duration * 24 * 60, venue_date + start_time) >= @StartDate As you can see there is some manipulation of dates. This sort of thing won't work because functions such...

asp.net mvc: SQLDateTimeOverflow problem with Entity Framework

I'm trying to update an object, and getting: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM. There are two fields in the object that are DateTime objects, and they're set with: obj.created_date = DateTime.Now; obj.modified_date = DateTime.Now; Except that everything looks reasonable when ...

Only parameterless constructors and initializers are supported in LINQ to Entities.

While trying a sem-complex query to display some ListView content on the page I got stuck on the famous "Only parameterless contstructor and initializers are supported in LINQ to Entities" error. Here is the code I used ... I can't find a place where I initialized something inside the query with parameters .... protected void ArtistsL...

Using an IEqualityComparer with a LINQ to Entities Except clause

I have an entity that I'd like to compare with a subset and determine to select all except the subset. So, my query looks like this: Products.Except(ProductsToRemove(), new ProductComparer()) The ProductsToRemove() method returns a List<Product> after it performs a few tasks. So in it's simplest form it's the above. The ProductCompa...

Entity Container and Model generation in different assemblies

I'm doing some refactoring and am trying to reuse my genertated entity models. My application has a few assemblies, one being my outward facing public types (API) and one containing implementations of providers (such as the log). I'd like to split the generation of the entities and models so that the entities will be in the API assembl...

Help with Linq to Entities simple subquery

I am learning Entity Framework and I am trying to get the following scenario to work. I have a Person class and a Message class. The message class has a From property and a To property, both of type Person. I want to retrieve a list of Messages using Linq to Entities. My DB tables are Message and Person. Message has columns From and To ...

LINQ generating SQL with duplicate nested selects

Hi. I'm very new to the .NET Entity Framework, and I think it's awesome, but somehow I'm getting this strange issue (sorry for the spanish but my program is in that language, anyway it's not a big deal, just the column or property names): I'm doing a normal LINQ To Entities query to get a list of UltimaConsulta, like this: var query = ...

Access SQL Server 2008 Change Tracking Info via Entity Framework

Based on this link it looks like I can get date inserted / date modified information "for free" (without the need for triggers etc.) using Sql Server 2008 by simply enabling Change Tracking. I am using Entity Framework to access the data. My question is, how do I access date modified / date inserted information for the database records...

Entity Framework and LINQ Include()

Hi I am new to Entity Framework and LINQ and have run into a rather odd scenario. I have been using the following query to return account information: var account = ((from acct in _entities.Account join m in _entities.Item on acct.Id equals m.Account.Id where acct.Id == accountId && m.It...

Linq to Entities Multiple left outer Joins in VB.NET

I am using Linq to entities which does not allow the .DefaultIfEmpty method. I need to know how to preform the following Multiple left outer join using Linq to Entities in VB.net select * from capitalrequests cr left outer join capitalrequestquotes crq on cr.ID = crq.CapitalRequestID left outer join la_vendor lv on crq.vendorid = lv....

IQueryable contains any of string array

I am not shore why IQuerable limits me when I try to search database for data containing string from an array. objectFactory.Resolve<IUserDao>().Query. Where(t => (spltedInput.Any(val=> t.LastName.Contains(val)) || spltedInput.Any(val=> t.Name.Contains(val))) && t.MasterCompany.I...

EF- How to do a 'Not In' using Linq to Entities

Hi- I'm using the Entity framework 3.5 and am having trouble running this query. I have the following entities: Applicant, application, and applicationstatusHistory (tracking job applicants) I'm looking for matches in Application where there are no matching applicationids in applicationstatusHistory with an id of -insert param here-. T...

Adding the results of two Linq expressions together

I have two similar tables which have data I need to display in a single grid. As each table has slightly different fields, I decided to extract the data I need into a generic object that I can bind to the grid. Shown below are the expressions I am using. My question is, how can I modify or add code so that I can get a single list that I ...

Searching in side an object's list of objects using lambda expressions?

I have 2 tables; they have a many-to-many relationship. One is called Blog the other is Tag. A Blog can contain a List of Tag objects. How can I go about getting all blogs that have a passed in tag name using lambda expressions? Thanks! ...

Creating a Linq statement to create objects

If I created a Linq statement as shown below, it works fine. var Jobs = from a in ctx.MyExport select new { FileName = a.FilePath, JobId = a.ID, }; If I want to use a class rather than an anonymous type I get the following error "Cannot convert lambda expression to type 's...

LINQ to Entites: how can I implement this complex t-sql in LINQ (multiple joins, DISTINCT, NOT EXISTS) ?

I have a complex query that I'm trying to reproduce in LINQ to Entities, but I'm not there yet - is it possible? The t-sql query looks like: select distinct C.id, L.id from dp join L on L.fk = DP.id join M on ( M.l_code = L.l_code and M.dp_code = DP.dp_code ) join C on C.c_code = M.c_code where not exists ( select id from map whe...

Why is this linq expression not working?

I'm using LINQ to Entities. I have a table called Student; it has ID and Name as it's columns. ID is a primary key. I'd like to be able select the name of the Student and get the amount of Students with the same Name. So for example I'd have this as my table data. ID Name 1 Bob 2 Will 3 Bob After performing the query I'd r...

LINQ to EF left join with multiple condition

I am trying to replicate the following SQL using LINQ to EF but with no luck. select * from Role left join QueueAccess on Role.RoleId = QueueAccess.RoleId and queueId = 361 Here's what I've tried. var myAccess = (from role in entity.Role.Include(p => p.QueueAccess) join qa in entity.QueueAccess on new { rID = role.RoleId, qID = queue...