entity-framework

Is there a quick way to convert an entity to .csv file?

at present, I have: string outputRow = string.Empty; foreach (var entityObject in entityObjects) { outputRow = entityObject.field1 + "," + entityObject.Field2 etc.... } I'm still new to the Entity Framework, is there a quicker way? ...

Can i get entity filled via Entity SQL ?

Hi. Can i do something like that: I got some entity Customer with Id, Name, Comment Now i want to get this entity from context with filled id and Name and Comment must be empty. I don't want to query it from database. in T-SQL it simply: Select Id, Name from Customers where id=4 Can i do that trick with Entity SQL something like th...

Entity Framework Tips, Tricks and Gotchas

Are there any ? ...

Dynamic Data query.Provider.Execute(query.Expression) analog for EF4

I'm porting a Dynamic Data project from L2S with DD preview 4 to EF with .NET 4. My custom code which works with MetaTable.GetQuery() results has stopped working. I have used the following code to apply ordering/filtering expressions to the MetaTable contents: public static IEnumerable GetOrderedItems(this MetaTable table) { var que...

Developing with SQL Server Express and delpoiyng with SQL Server 2008?

I'am developing a web application with VS2010 Entity Framework and SQL Server Express. This application will be deploiyed in a server with SQL Server 2008 (not express) It is possible? What changes (if needed) i need to do? ...

Entity Framework Contains method and objects

Hi, Is there a way of using the Contains method in Entity Framework 4 with the actual id of the object? Take these entities as an example: public class Order { public int OrderId { get; set; } // PK public string CustomerId { get; set; } // FK to Customer } public class OrderItem { public int OrderId { get; ...

Best strategy for adding or updating a collection of related entities when using the EF4?

Let's say you have a Classroom entity with an collection of Student entities. What I usually do when creating a new Student and need to add it to the Classroom is use Classroom.Students.Add(newStudent), now when I want to update this collection I normally clear() the collection and add the students again, something like: theClassroom.St...

EF4 Update Entity Without First Getting Entity

How can I update an entity without having to make a call to select it. If I supply the key for the entity, should it not know to update after SaveChanges() is called on the ObjectContext. I currently do this: var user = context.Users.Single(u => u.Id == 2); user.Username = "user.name"; user.Name = "ABC 123"; context.SaveChanges(); Th...

EF : DeleteObject() in foreach loop

With Entity Framework, I try to delete some objects from my object context like that : foreach (var item in context.Items.Where( i => i.Value > 50 ) ) { context.Items.DeleteObject(item); } With this code, I have a "Collection Was Modified" Exception. So, how can I do a batch delete ? ...

ASP.MVC2.0/EF4.0 site deployment/maintenance

Hello, My small team used asp.mvc 2.0/entity framework 4.0(model first approach)/Windows Server 2008r2/Sql Server 2008 r2 stack in out web site project. We've already complete developing process, and come to the web deployment stage. In this stage we are faced with the problem - ok we'll use vs2010 features for initial server/db deploy,...

Entity framework: How can I use more then one context?

Hi, I'm new with EntityFramework. My application has a pool of context object instances (Each context has 1 connection to the DB). The problem is that when I update an object (and calling SaveChanges), the data is updated in the DB and in the updating context but when I select from other instance, it gets the old data of the selected ...

Entity Framework - Problem with querying nullable column

Hi, I have a problem querying data from a table with a nullable tinyint column. The problem seems to be that the query is generated as: AND ( CAST( [Extent1].[PositionEffect] AS int) = @p__linq__3) => @p_linq_3 = NULL If i run that query manually it doesn't turn up any results. However, when I replace the query with: AND ([Extent1]...

Entity Framework - load data from table with 1:1 table involved using one query?

Hello, I have the following command: var query = from x in context.FirstTable.Include("SecondTable") where x.TestColumn == 5 && x.SecondTable.SecondTestColumn == 3 select x; Now I also want to load the entries from a third table named "ThirdTable". But I can only reference it via the SecondTable table. There is a foreign key from Fir...

After Deploying ASP.NET 4 web application to IIS6 server, worker process recycles cause it to stop working most of the time

This is a really odd situation, so hopefully I can explain it well enough. I am deploying an ASP.NET 4 webforms application to a Windows Server 2003 SP2 server running IIS6. Here's the problem -- when the application pool recycles its worker process (w3wp.exe), about 80% of the time, I will get an ReflectionTypeLoadException error t...

How do I use ENTITY DATASOURCE to Insert Data into a TABLE using OnInserting Event ?

I have two tables: AspnetUsers Userid uniqueidentifier NOT Null PK UserName Nvarchar (256) NOT Null More column More Column UserProfiles UserId uniqueidentifier Not null PK FK Default (newid()) Username Nvarchar(256) Not Null More columns, More More columns There is a constraint between the 2 tables. When a user is insterted...

context.detach - for garbage collection

My application uses one context instance which exists for the life of the application. I am using Entity Framework to read and write all data to the database. After I add objects, I want them to be cleaned by the garbage collector so they don't persist in memory. I've tried: While context.BatchProgresses.Count > 0 context...

stored procedure mapping Entity Framework

Hi, We're using a Function Import in an EF4 model to populate an existing entity in our Model. The entity in the model has a Key field of Id which we're struggling to map as our stored procedure doesn't return an Id field. I've tried setting the value in the mapping to a literal value of 0 but that fails with an EntityCommandExecution...

DataAnnotation attributes not working in Asp.Net MVC2

Hello, I am having trouble with the with mvc2. I am using the Entity Framework as my ORM. I have used the POCO Entity Generator to create POCO objects. I moved the generated objects to a separate project. I followed steps outlined here(Tutorial). This is my project structure Sports.Data - Entity Frmework and Data Access Sports.Entiti...

ASP Repeater with Linq to entities object - child list problem

Hi I have a Linq CodeBehind Function Like this var result = from m in context.Products.Include(n=>n.Categories) where m.IsActive == true select m; The m is Product Class which holds the list of categories. On the ASPX page in repeater I want to have acces to first category where my product is. I trie...

Amending Gridview according to table properties.

Hello all. I shall attempt to explain the scenario. I have a gridview I wish to amend according to the preferences a user may set. These preferences being stored within a table in a EDMX (tblPref). The table gives the prefernce i.e. Product, the Alias for the preference i.e. SKU and whether the Preference should be shown i.e. ShowProdu...