entity-framework-4

Data Annotations in MC2 - Issue with base class validation

I have an Entity Framework 4 model first layer, where I have a Product base class and then different classes that derive from the class. For each type of Product there is a Partial Class, and then each of the partial classes uses a buddy class for Data Annotations. [MetadataType(typeof(Product_Validation))] public partial class Product ...

Entity Framework: Substituting Primary Columns for Foreign Key Columns

I've created a new ASP.NET website. I've generated an Entity Data Model from my database and have dropped a entitydatasource and gridview onto my page and wired up the gridview to pull from the entitydatasource. Now I get columns like this: id extension prefix did_flag len ten_id restriction_class_id sfc_id name_display buil...

Create multiple tables from 1 class at runtime

Hi, Is it possible to have a class X and create multiple tables from it using the Entity Framework 4, code first, during runtime? For example class Item. I want to create table ItemA and table ItemB. Can this be done at runtime? ...

Entity Framework: Metadata when Entity Name is Same as Property?

I have a EDM with a entity "Extensions" - within this object is the property extension. I've wired up all the other columns just fine, but this one refuses to wire up. I'm guessing because the entity and the property share the same name? Here is my code, the extensions doesn't work, the prefix does work: Imports System.Web.DynamicData I...

Entity Framework: Update Entity when Another Entity is Updated

I have an EDM, it includes the entities extension and history. My goal is to use history to keep track of all the changes made to extension entity. For example, if extension with ID 223 has its property 'Name_Display' changed - I want the history entity to record this. I'm using ASP.NET with VB.NET. Where in my code do I put the hook to...

Asp.NET MVC 2 EF4 Dynamic Proxies

Hi. Im working on Asp.NET MVC 2 project with EF 4(POCO, Lazy disabled) and have a problem with DynamicProxies generated by EF runtime. I have strongly typed partial view for EF POCO class ie Property, but from EF context i get Property object wrapped by Dynamic Proxy Class, so after calling RenderPartial i get this error: The model it...

How do I get the identity field after insert on dynamic data form (entity framework)?

Hi people, I have a Dynamic Data custom page with a child formview that connects to the main formview with a query extender via a controlfilterexpression As per the first diagram: http://msdn.microsoft.com/en-us/library/dd985039(VS.100).aspx# I've hooked the ItemInserted event and would like to call an insert on the child using the id...

Filtering collections in Entity Framework 4

I have been testing out EF 4 and am looking to filter child collections on an object. I'm using POCO support and have EF wiring up my collections automatically: public virtual ICollection<Product> Products { get; set; } So in this example, I can get an instance of a category and then enumerate it's products. What I want to k...

Entity Framework: Create Change History

I have a EDM (phoneDB) that models a back-end MSSQL database. I've developed a ASP.NET (VB) application that allows one to edit the information in this database. When someone edits a record entry I'd like to record this action. Right now, I'm doing the following: For Each..Next that checks whether entry is an object that has had its...

Entity Framework: How to update database when modifying Model

Hi In Entity Framework 4 there are the options "Update Model from Database" and "Generate Database from Model". But what I'm missing is an option like Update Database from Model which reflects the changes made in the model (e.g. adding a new Property or Navigation-Property) by modifying the database schema (e.g. adding a n...

Get Specific Value from entity.OriginalValues in EFv4

I have an ObjectStateEntry "entry". I need to get a property value from this "entry" like so, but I don't know how to specify the property I want. I use entry.OriginalValues(propName) but then what? ...

Entity Framework: Save Object?

Here is my code: Partial Public Class AppsEntities Private Sub OnContextCreated() AddHandler Me.SavingChanges, AddressOf context_SavingChanges End Sub Private Shared Sub context_SavingChanges(ByVal sender As Object, ByVal e As EventArgs) For Each entry As ObjectStateEntry In DirectCast(sender, ObjectContext).ObjectStateManager.G...

HiLO for the Entity Framework

Has anyone implemented a HiLO key generator for the Entity Framework. Read more about HiLo here: I recommend that you read http://fabiomaulo.blogspot.com/2009/02/nh210-generators-behavior-explained.html for a detailed explanation of the downsides of choosing identity. ...

Sorting EntityFramework computed columns

Hi, How do I handle sorting in RadGrid (or any other Grid) using EntityDataSource on computed columns ( in EF partial classes eg.: DisplayName { get { retrun this.Name + " " + this.LastName;}} ) ? ...

How to return values from a dynamic SQL Stored Procedure to the Entity Framework?

I have a Stored Procedure which executes some dynamic SQL. I want to use this Stored Procedure in entity framework 4, but when I try to create a complex type the procedure returns no columns. Is there any way I can force it to return my values and get the entity framework to receive them? Here is a much-simplified example of what I want ...

Change Entity Framework 4 Mapping after build

I am wondering if Entity Mapping inside .edmx files/.MSL file can be changed after the project has been built and deployed? ...

Retaining table relationships through views with Entity Framework 4

Using Entity Framework 4, I am creating the EDMX from a database. The database has views in addition to tables. When I select the views to generate from, the resulting model does not retain the relationships that exist between the underlying tables. Does anyone know how to retain these relationships for the views? I want to be able to wr...

Manipulating FormView values pre and post bind/db operation?

Hi, guys. I have two FormView controls on an asp.net page using an EntityDataSource. I'd like to hook the ItemInserted event of the first one, get the identity field of the insert and use that identity in an insert call of the second. Is this possible? I figured I can get the identity from hooking the Inserted event of the EntityData...

Is it possible to use EF 4.0 without having a dependence on .NET 4.0

Lets say I build an Service Layer wich deals with POCOs coming out of an repository. The Repository is aware of the EF 4.0 and deals with POCO generation and so on. But that does also mean that my Repository will have a .NET 4.0 dependency and so my Service Layer which consumes the Repository will also have a .NET 4.0 dependency...even i...

Switching in Entity Framework 4 between SQLCompact and SQLExpress storages

Here's the use case In SQLExpress I have created a table Posts with columns ID and Name edmx is created based on that table I create the SQLCompact database with the same structure (table name Posts, columns ID and Name) If I update the app.config to point to the SqlCompact DB (presuming I do that in correct way), would EF code work...