entity-framework

ASP.NET MVC saving Entity session

Hi, I have been working with entity framework and ASP MVC for a while. I have stored the entity object in the HttpContext.Current.Session in order to use the same session at all times. Now I have encountered some problems and I am wondering if this may have been a bad idea and if so, how should I do it otherwise. The problem I have now...

Soft Deletes ( IsHistorical column ) with EntityFramework

I'm working with a database where the designers decided to mark every table with a IsHistorical bit column. There is no consideration for proper modeling and there is no way I can change the schema. This is causing some friction when developing CRUD screens that interact with navigation properties. I cannot simply take a Product and t...

Will the Entity Framework 4 work with MVC 2 - since MVC is based on 3.5?

Can I use the upcoming Entity Framework 4 with aspnet mvc 2 since mvc is based on 3.5? ...

How do you update a table with a foreign key to another table in ADO.Net Entity Model?

I have 2 tables, Table1 has a primary key 'CustomizationId', and Table2 has a FK Customizationid which matches this. Table2 has no primary key. I am trying to add a new record from a web based form. I attempt to save this to the database and I get an error: Customization customization = new Customization(); Code...

Inserting a record with specified primary key into MySQL via Entity Framework

Hello, We began using Entity Framework with MySQL in our project recently. Now I am writing unit tests for the data access level; for that purpose I have created a database with some test data. In the test-method for the Delete method I want to first delete a specified record and then insert it again with all the fields holding exactly...

Entity Framework - Deleted association still appears in the second call

Hi, We have a long entity framework context running (don't ask why...), with a query which retrieves a user entity with its associations: var user = entities.UserSet.Include("UserAddresses") .Where(u => u.Id == 1).FirstOrDefault(); If a row of a user address is deleted from the database (by another process), and we ...

Linq, Entity Framework and WCF

If I have a customers and orders relationship in my Linq or EF model, at the WCF service layer I can add an order to the customer by calling Customer.Orders.Add(customer); When I access my customer object on the client, and want to add an order, there is no Add method, and the Orders propery is an array. Is there any way I can work w...

Entity Framework ObjectContext in windows/WPF/Silverlight application

We are writing a WPF application using Entity framework (Silverlight with RIA services to be precise). We're using a shared ObjectContext through the application so that we can benefit from sharing data across the modules. The problem is - if user during his work opens let's say historical sales, it gets loaded to the ObjectContext and ...

How can I do an eager load when I don't know the name of the property I want to load?

I have a generic repository and when I'm using a DoQuery method to select objects from the database, I need to load some of the related entities in order to not get nulls in the place of the fields that are foreign keys. The problem is that the repository is generic, so I do not know how many properties need loading or what their names ...

Learn LinqToSql or stick with ADO.NET?

I'm debating what technology to use for an upcoming ASP.NET project. Assumptions: I will be using Visual Studio 2008 SP1 (.NET Framework 3.5) The back-end will be a SQL Server 2005 database (or possibly 2008) Code will be written in C# I already have experience with LinqToObjects and LinqToXml I also have experience with ADO.NET and s...

Scalar Property and Navigational Property EDMX

What is Scalar property and Navigational Property in Entity Frame work Model? ...

How to manage optional one-to-many relation with EDM?

Hello, I have relation 0..1 to N, for example between drivers and cars. So one driver can be assigned to many car, but one car to many drivers. However I want to have possibility of assigning no driver to car. So should I have field which allow nulls and has null as default value for this field? If so, then what value should I have in d...

Impersonating user with Entity Framework

So we have our web app up and going with entity framework. What we'd like to do is impersonate the current user when we're accessing the DB. We're not interested in setting impersonation up in our web config. Ideally using something like this: http://geekswithblogs.net/jkurtz/archive/2007/08/27/114992.aspx when we're about to acces...

How do I to check if a entity is in a many-to-many relationship.

I have a 'user' table, a 'phone number' table and a 'user to phone number map' table. The phone number table stores only unique phone numbers. This way I can take a look at a phone number and see who is using it easily. It is also easy to check if a phone number exists when the user is edited. The question is how I should be checkin...

Entity Splitting with Code Only

Is their a way using Entity Framework Code-Only to have an entity that has fields from two tables if both tables don't contain the primary key? Here is an example. public class BlogPost { public int PostID { get; set; } public String PostBody { get; set; } public int UserID { get; set; } public string Username { get; se...

ADO Entity framework help

Having some experience with Linq to SQL I'm trying out ADO Entity framework now. In Linq to SQL, I would create a Linq to SQL class, drag my tables across to build the data context. Then I'd instantiate the datacontext class and run some lambda against one of the properties in the datacontext class. Now, with ADO entity framework I ad...

Entity Framework - joining nulls - NullReferenceException was unhandled by user code

I am writing an asp.net mvc application to learn Entity Framework with and am running into an issue that I do not know how to handle. For simplicity lets take the following table structure: Movie ID (int, not null, auto increment) Name (varchar) GenreID (int) and Genre ID (int, not null, auto increment) Name (varchar) M...

How to do a left outer join wtih an include in sub query?

I have a table which I am querying via Entity Framework: using (Entities context = new Entities()) { var customizations = context.Customizations.Include("aspnet_Users").ToList(); } However, I want to included another table, "SelectedCustomizations" as a LEFT OUTER JOIN into the above query. Any ideas? ...

Entity Framework - MySQL - Null Comparison!

Whats wrong with following code? :( int? parentFolderId = null; if( this.Request.QueryString ["folderId"] != null ) parentFolderId = Convert.ToInt32( this.Request.QueryString ["folderId"] ); f = ( from x in this.EntityDataContext.folders where x.parent_id == parentFolderId select x ).ToList(); It returns nothing! Though there ARE...

Entity Framework throws SqlDate exception on the *lookup* table

I am using Entity Framework with asp.net mvc, but I don't think mvc plays a big role here. I have an object Customer, and a lookup table (there are several, and they all behave the same way; so for simplicity I'll pick Territory). Both Customer and Territory have LastUpdated field (Datetime that is set manually in the code). If I hardc...