linq-to-entities

How to convert Linq to SQL to Linq Entity?

hi I have the code below could you help me please to rewrite from LINq to SQL to Linq to Entity. thank you if(account.AccountID > 0) { dc.Accounts.Attach(account, true); } else { dc.Accounts.InsertOnSubmit(account); } dc.SubmitChanges(); ...

Entity Framework 4: Returning IQueryable or ObjectQuery when using LINQ to Entities?

Hi there, i have been reading when using Linq to entites a query is of type IQueryable before it is processed but when the query has been processed, it's no longer an IQueryable, but an ObjectQuery. In that case, is it correct to write methods from my layer (repository layer) to return IQueryable? Do i need to cast? Why would i want ...

linq to entities orderby strange issue

maybe foolish question, first times with linq to entities (well, linq in general). table with id(int), value(decimal), name(string) for each record i need id list<string> id value name THE FOLLOWING WORKS FINE int pageSize=10 int pageIndex=2 var data = (from c in db.Customers orderby c.ID selec...

Implementing a "like" operator multiple times in one Linq to Entities query

We have a list of strings and we need to filter our results by that list. Example would be find all students who have SSNs that start with 465, 496, or 497 (plus x more) List<string> list = GetPossibleStartsWithValues(); var qry = from student in entities.Students.WhereStartsWith(x=>x.SSN, list) select new SearchedStudent { Name ...

How can I implement the following SQL query as linq to entities query?

How can I implement the following SQL query as linq to entities query? select *, MIN(QueuedDate) from pcm_transactions where QueuedDate IS NOT NULL And ExecutionDate IS NULL group by SimId I spent hours thinking and trying varius methods - hope to find the right answer here. EDIT: Here is one of my first tries: // Get the oldest q...

How do I make an "Except" LINQ to Entities query?

I have a many-to-many relationship between Accounts and PaymentSystems. I want to list all PaymentSystems not yet assigned to an account. To achieve that, I'm trying to use the following LINQ to Entities queries: PaymentGatewayEntities pge = new PaymentGatewayEntities(); Account account = pge.Accounts.Single(item => item.id == accountId...

What is Linq to Entities?

There are so many terms and it is getting hard to learn the thing you are after because of the noise. Is Linq to Entities just the practice of using Linq queries against the entities generated by the ADO.NET Entity Framework? Or, is it a separate technology? If it isn't a separate technology, why does it have another confusing name as ...

Dynamic queries in LINQ to Entities

Using TSQL stored procedures, dynamic queries were a cinch. For example, say I had a reporting application that optionally asked for archived records. The stored procedure would look like so: DECLARE @sql nvarchar(MAX) DECLARE @join nvarchar(MAX) DECLARE @where nvarchar(MAX) IF @optionalvar1 IS NOT NULL SET @where = COALESCE(@where...

How do I get Entity Framework to only update the Properties modified in the SQL generated?

I am using Entity Framework with the Self-Tracking Entity T4 templates, which by default will generate a SQL Query setting all the properties on the Entity in an UPDATE statement. I only want an UPDATE statement that contains the properties modified. I modified the T4 Template as specified in the book: Entity Framework Recipes: A Probl...

LINQ Find non overlapping audit records by date

I have an audit table which stores audit rows for a long running process at an individual task level in SQL Server. auditId int, TaskName nvarchar(255), StartTime datetime, EndTime (datetime, null), Status (nvarchar(255), null) The process contains parent and child steps and each step is logged to the audit table. A task may or ma...

What to return from my linq to entities query

So I have a data access class library I make a linq to entities call I end up with a single row that has my TableData object. What should I return back from my class library method? I thought it would be cool to return back the TableData object, but I see that if you make changes to it and call a save that it actually updates the dat...

Testing Linq to Entities Queries

What is the best way to do this? Typically when I create a Query in SQL I create it in the designer of visual studio and I run it multiple times to see my results.... Is there such a thing for Linq-to-Entities? ...

Creating a list of .Include() in linq to entities

I have a long list of includes: .Include("x") .Include("y") .Include("z") .Include("z.w") .Include("z.v") I would like to use this list on three different queries. How can I put these in a list and use that list in all my queries in order to not repeat myself. ...

Getting Entity Framework Error: Invalid object name 'Navigation'.

I have an Entity Object called Navigation stored in a Database called Navigations. When I save the Entity calling context.SaveChanges(); I get the error Invalid object name 'Navigation'. I have removed the model and added it back in but with no change. Does anyone have any ideas? ...

Linq Expressions and Aggregate classes

How do I build Linq Expressions for aggregate classes? Let me explain with an example of what I am trying to do. Say, I want to find all employees with pay not equal to 50000 and here's the class structure. Employee e1 = new Employee { Name = "Jane", PDetail = new PayDetail { Salary = 100000 } }; Employee e2 = new Employee { Nam...

binding gridview with my getall method - entity framework

Ok please excuse my references to the gridview. So i have this method in a class called getall() what this does is gets the collection of entites from entity framework model for a specfic table, checks to see whether the table exists and then does the query using linq (linq to entities). This does work as I have used a breakpoint and ev...

LINQ to Entities many to many relationship

I am new to LINQ and the Entity Framework and am having trouble coming up with a suitable query. I have the following entities. I have included primary keys and some other relevant fields. Contact Int ContactId(PK), String Name, String EMailAddress Project Int ProjectId(PK) ProjectContact Int ProjectId(PK), Int ContactId(PK), Boolean...

Is retrofitting Entity Framework into my app appropriate for my situation?

So, I have an app that uses a SQL Server express db. I have about 80ish tables all with a primary key but no foreign keys. (The reason we have no foreign keys is because of how we do our sql client-to-server replication. It's not true replication but it's a sync system that was in place when we took over the app. We have no guarantee wha...

Entity Framework Views and Linq .Where

I have a very small entity framework setup containing only a few related classes/tables and a view. I need to be able to pull a specific record from this view, namely, I need to be able to grab the record that meets two criteria, it has a specific ProfileID and a specific QuoteID. This line is what's causing the problem: TWProfileUpcha...

IQueryable: Creating dynamically an OR filtering

I have a set of search criterias in this form: member | value | operator --------+---------+--------- height | 10 | > height | 2 | < name | Carl | == And I want to query all the objects that match any of these criterias. Right now, I'm doing it by: building an expression for each one of the crit...