linq-to-entities

Linq to Entities - eager loading using Include()

Hey Everyone, I've got this really basic table structure: dbo.tblCategory dbo.tblQuestion (many to one relationship to tblCategory) dbo.tblAnswer (many to one relationship to tblQuestion) So basically, what I'm trying to do is when I load a category, I want to also load all Questions, and all Answers. Now, I've been able to do this...

Silverlight linq-to-entities Anonymous type problem

Hi, I am trying to work with silverlight, wcf data services ( on the website code) and Linq-to-Entities. I know that anonymous types don't work on silverlight then I created a known class in order to retrieve some information. (I know the query it is not exactly intelligent, but It is only an example) but It is not working. can somebody...

How to see LINQ generated SQL in Visual Web Developer 2008 Express Edition?

Hi all, can someone explain me how to check LINQ generated SQL queries in VWD 2008? I just have not enough time for figuring it out by myself, so any help is appreciated Thanks EDIT: I am using SQL Server 2008, Entity Framework and ASP.NET MVC ...

LINQ Select Method Issues With Fluent Interface

I'm using LINQ-to-Entities. Using the following query: var x = from u in context.Users select new { u.Id, u.Name }; That only selects the Id and Name columns. Great. I'm trying to make a repository that can be passed that new { u.Id, u.Name} as a parameter to allow the client to pick which columns are used in the SELECT statement. ...

why SaveChanges invokes when i'm debugging?

I am developing application using Entity Framework. When i'm in debugging mode my test values are saved into database when i exit debugging even if i'm not hitting SaveChanges method. Why is this happening? I spent 4 hours trying to figure it out, but had no luck.... Even if i have my breakpoint at the start of the action, and i ex...

Group by is not working on WCF Data Services

I have this code, Data Summary is a class, it is not an entity. I use it for the anonymous type on "select new" public class DataSummary { public DataSummary() { } public int AccountID { get; set; } public decimal Total { get; set; } } then I have this query DateTime date...

Asp.Net MVC double submit/request breaks SQL connection

Hello all, I am running into a strange problem I don't fully understand. The main symptom is that when I double click a link (that points to a controller action) in my MVC application, my database server connection gets blown, and I get the error : Execution of the command requires an open and available connection. The connection's cur...

Linq to Entity Framwork 4 query counting but not returing results.

I have a query like: var fooQuery = (from x in edm.stuff where x.col == DesiredVal select x) 'stuff' is a view. When I count the results I get '1'. When I First() or FirstOrDefault() I get null. var fooCount = fooQuery.Count(); // results in 1 var fooResult = fooQuery.FirstOrDefault(); // results in null This doesn't make sense t...

How can Entity Framework queries be reused (using methods)?

I'm trying to reuse part of a query, because it's complex enough that I want to try to avoid code duplication. It seems that when calling any method inside a query, you end up with: LINQ to Entities does not recognize the method {X} method, and this method cannot be translated into a store expression What I would like to do...

Linq Entity Framework generic filter method

I have some methods which perform a standard filter on data from my Entities (using Entity Framework v4). Example #1: protected IQueryable<Database.Product> GetActiveProducts( ObjectSet<Database.Product> products ) { var allowedStates = new string[] { "Active" , "Pending" }; return ( from product in products w...

How do I write this Linq-to-Entities Query in Vb.net?

This is what my entities look like: I'm essentially trying to make a left outer join between LookupMakeModel and LookYearMakeModel for a given year. I plan on selecting a valid year from a dropdownlist and then showing a table of all the records in LookMakeModel and checking the checkbox for the LookMakeModels that have a record in L...

count + group by + where

I'm using Entity Framework 4 and having trouble with a query. I have two objects: Instruction Component Between these objects there's a many-to-many relation. An Instruction van point to one or more Components. And a Component can be referenced by multiple Instructions. I am trying to get how many 'finished' (status = 6) Instructions...

Inserting multiple rows into a table using Entity Framework

Hello all. I’m having fun with EF and have come unstuck. Originally I used the following bit of code using standard linq that essentially enters some data into a table. ManagePreferencesDataContext manpref = new ManagePreferencesDataContext(); tblManagePreference prefMemberID = new tblManagePreference(); ...

LINQ to entities - best practices for passing models

As we all know most apps have a data access layer, often using repository classes. Typically we want the repository to operate with strongly typed objects, e.g. interface IUserRespository { User GetUserByID(int id); void AddUser(User u); ... and so on } However, sometimes we want to make a more complex query on a DB, ...

Rewrite SQL query using Linq to entity.

Hi guys I need to rewrite the sql query below using Linq to entity. Unfortunately I don't have a lot of experience of using Linq. Please help me With TempTableName AS (SELECT [ColumnName], [ColumnName2], [ColumnName3], [ColumnName4], ROW_NUMBER() OVER (order by ColumnName desc) as RowNumber from TableNam...

LINQ to Entities does not recognise the method 'System.Web.Security.MembershipUser GetUser()Method'

I have (well had) a bit of code that would get me my lovely username and populate a session with its contents: ManagePreferencesDataContext lg = new ManagePreferencesDataContext(); IEnumerable<tblManagePreference> ol; ol = from login in lg.tblManagePreferences where login.Username == Membership....

Linq Entity Framework -- can I use a recursive method?

Following on from the excellent answer to my previous question: http://stackoverflow.com/questions/3220155/linq-entity-framework-generic-filter-method I am now trying to understand how I can apply something like recursion to my solution. To recap, instead of multiple similar declarations of this method: protected IQueryable<Database....

How can I set custom property of an Entity type in LINQ to Entities query and still return a IQueryable<T> ?

Hi, I have a EF4 model where I have Product entity that have one-to-many relation with Task entity (ChildTasks). I have to get some Projects from db based on some user criteria. The Project has one custom property (not associated with any column) named EstimatedProgress where I have to store additional information about Project - compute...

How to partially load entity framework POCO

I have an EF 4.0 model that has a parent child relationship (say order and orderdetails) order { [primative] orderid, ordername, ordershipping [navigation] orderdetails } orderdetail { orderdetailid, orderpartid, orderquantity, orderpartname } My question is how do i load orders with orderdetails where the ...

LINQ to Entities updating multiple rows

I am new to LINQ to Entities and need some guidance about how to think about multiple row updates. My problem is actually more conceptual than syntactical as I am not sure if I am even thinking about the solution correctly. Here is a single row update. This seems very straightforward. products prodtbl = (from p in db.products where p....