linq-to-entities

When selecting an anonymous type with LINQ from EF, is there no way to run a method on an object as you select it?

Let's say I have a method: bool myMethod(int a) { //return a bool } So let's say I the following // assume a has prop1 and prop2 both ints var mySelection = from a in myContainer where a=somecondition select new { a.prop1, myMethod(a.prop2) ...

Linq to Enities: Result set not getting updated after Stored Procedure Call

In LINQ to Entities, I map the result set of a stored procedure to an entity. Within the stored procedure, I execute some update statements and return the result set by running a SELECT query and mapping that result set to the entity. The database rows get updated correctly, but the entities returned are not reflecting the changes. Ins...

Entify Framework Inserts require Select permissions

We use LINQ to Entities to write entries into an Audit database (SQL Server 2008). Since this is a dedicated Audit database, we only insert rows - we never read any rows, update or delete them from the auditing application. The auditing application should use the principle of Least Privilege, so we don't wish to grant it more permission...

Using "cached" LINQ entities

Hi, i've got the problem that i implemented a WCF-service which is using LINQ entities... To generate the content of the response to a service call, requires a high amount of LINQ/SQL selects... Whatever, the service is not doing any updates or inserts to the DB, so i'd like to implement a kind of "caching" of the LINQ entities ( also ...

Linq to entity timing problem

Hello, I created a data model that has some views from my database as entities,when I create a linq statment that has part of this view's entities ,the time processor take to execute the linq statment is very long.. can anyone help? ...

Passing func as parameter in Linq to Entities and 'Internal .NET Framework Data Provider error 1025' error

We have a class called Task: public partial class Task : EntityObject { public EntityCollection<TaskUser> TaskUsers { get {...} set{...} } } It has navigation property called TaskUsers, which contains users attached to this taks: public partial class TaskUser : EntityObject { public User User { get {...} set { } } } Every...

Using static data access methods with the ADO.NET Entity Framework

Hi I am using the ADO.NET entity framework for the first time and the staticcode analysis is suggesting I change the following method to a static one as below. My question is simple, is this thread safe? public static void InsertUserDetails(UserAccount userAccount) { using (KnowledgeShareEntities entities = new Kno...

Linq to enties, insert foriegn keys

I am using the ADO entity framework for the first time and am not sure of the best way of inserting db recored that contain foreign keys. this is the code that i am using, I would appreciate any comments and suggestion on this. using (KnowledgeShareEntities entities = new KnowledgeShareEntities()) { Question...

asp.net mvc many-to-many one-to-many

Hello, I am new in asp.net MVC, and in Entity Framework to. I watch on asp.net mvc tutorials, but they are very easy. I need to write little site, and in my database have one-to-many reletionship. if i want to select data from two tables (classic inner join), what you recommended to use, db views or Linq to Entity queries. If Ling to Ent...

LINQ-to-Entities select clause containing non-EF method calls

I'm having trouble building an Entity Framework LINQ query whose select clause contains method calls to non-EF objects. The code below is part of an app used to transform data from one DBMS into a different schema on another DBMS. In the code below, Role is my custom class unrelated to the DBMS, and the other classes are all generated ...

asp.net mvc: how to create custom binding for models when using LINQ to Entities

I've got a number of tables in my db that share common cols: modified by, modified date, etc. Not every table has these cols. We're using LINQ to Enties to generate the I'd like to create a custom binder class that can handle the automatic binding of these fields. Is there a way to do this without having a custom binding class for e...

How can i write Linq2Entities Query with inner joins

How can I get data from these related entities. I want to get these columns only: Term.Name , related Concept_Term.Weight, related Concept.Id I wrote the SQL but I don't want to use select t.Name,ct.ConceptId,ct.Weight from Term t inner join Concept_Term ct on t.Id=ct.TermId inner join Concept c on c.Id=ct.ConceptId where...

Problem getting GUID string value in Linq-To-Entity query

Hi, I am trying to write a GUID value to a string in a linq select. The code can be seen below (where c.ID is GUID), but I get the following error: Unable to cast the type 'System.Guid' to type 'System.Object'. LINQ to Entities only supports casting Entity Data Model primitive types. var media = ( from media in Current...

Linq-to-Entities: Format Date in select query expression

I am trying to get a formatted date string directly from a LINQ-to-Entities query expression. nonBusinessDays = (from ac in db.AdminCalendar where ac.DateTimeValue >= calendarStartDate && ac.DateTimeValue <= calendarEndDate && ac.IsBusinessDay == false select ac.MonthValue + "/" + ac.DayOfMonth + "/...

SQL Server Query Execution Plan Rebuild

I have this query that gets executed though Linq to Entities. First time the query runs it generates the execution plan which takes just under 2 minutes. After the plan is cached the query takes 1 or 2 seconds. The problem I have is that the plan keeps getting rebuild every few hours and I am not sure why that would be? This is the linq...

asp.net mvc and linq to entities: how to include text value from IEnumerable<SelectListItem>

I have a table with a constraint on one field - it can be 1, 2 or 3. (The correct solution to this is probably to create a lookup table for this, but for now I'm wondering if it's possible to do this without the lookup table.) I've created a class that returns an IEnumerable for the values. I'm using LINQ to Entities, and would like t...

LINQ Training: Native SQL Queries to LINQ

Can anyone point out some good LINQ training resources. Mostly interested in getting some developers that are very skilled with SQL up to speed using Lambda and LINQ queries. They are struggling with some of their more advanced queries and fall back on ExecuteQuery() to kind of do the LINQ thing. Queries that used to be easy in TSQL but ...

Entity Framework Many-To-Many with additional field on Joining Table

I have an entity context that includes three tables (see diagram here). The first is a table that contain products, the second contains recipes. The joining table has fields for IDs in both the products and recipes table as well as a 'bit' field called 'featured'. I've searched and found no example on how to insert only how to select a...

Linq Entity Inheritance makes BIG SQL Sentences

We are developing an application with a base entity with more than 10 childs (which inherited from it). When we make any request with Linq to the base entity we get a SQL statement with a "UNION ALL" for each child. To make a Count() over the base entity it takes near one second and getting only one row can takes two seconds. For this ...

Linq, Where Extension Method, Lambda Expressions, and Bool's

Greetings, I am having some issues with using a bool operation within a Where clause extension method of an IQueryable object obtained using Linq to Entities. The first example is showing what does work using Bool1 as the operation I need to move to a where clause extension method. The second example is what doesn't work after the chan...