Feature CTP Walkthrough: Self Tracking Entities for Entity Framework

Published 22 June 09 01:16 PM | dpblogs 

Overview

The goal of the following walkthrough is to demonstrate a basic scenario for the use of Self Tracking Entities with Entity Framework. Self Tracking Entities is a feature included in the Microsoft Entity Framework Community Technology Preview 1, which consists of a new API added to the ObjectContext and ObjectSet classes (implemented as extension methods for the Feature CTP) and a code-generation template based on Text Template Transformation Toolkit (T4) technology included in Visual Studio.

Self Tracking Entities are domain classes that do not have any dependency on Entity Framework but include mechanisms that allow them to track changes on scalar and complex property values, references and collections within themselves, independently of the Entity Framework.

The first scenario we are trying to address with Self Tracking Entities is one in which a WCF service exposes a series of operations that return entity graphs, then a client application can manipulate that graph and submit the modifications to a service operation that validates and performs the updates to a database store using Entity Framework.

Requirements

  1. This walkthrough requires Visual Studio 2010 Beta 1
  2. The Microsoft Entity Framework Feature CTP1, that can be downloaded from here.
  3. A local SQL Server 2008 Express instance has to be installed as SQLEXPRESS. Otherwise, changes to the connection string in the web.config file or regenerating the database from the included SQL scripts may be necessary.
  4. Download and extract the initial solution attached to this post.

Read More...

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Feature CTP Walkthrough: Self Tracking Entities for Entity Framework | ASP.NET MVC said on June 23, 2009 12:24 AM:

PingBack from http://aspmvc.co.cc/2009/06/22/feature-ctp-walkthrough-self-tracking-entities-for-entity-framework/

# progg.ru said on June 23, 2009 1:11 AM:

Thank you for submitting this cool story - Trackback from progg.ru

# Matthieu MEZIL said on June 23, 2009 1:59 AM:

Avec VS 2010 Beta 1, il manquait quelque features pour lesquelles l’EF team avait communiqué en disant

# radyo dinle said on July 19, 2009 10:43 AM:

Thank you for submitting this cool story

# Nabil Sedoud said on July 31, 2009 2:06 PM:

I make a test for this Walkthrough by using code only Context, and i receive this error "underlying connection was closed: The connection was closed unexpectedly"

I think that there is an incompatobility when use T4 SelftTracking with CodeOnly approche.

unfortunately it's an other limitation of EF

# tangrl said on August 7, 2009 12:39 AM:

Will the new Entity Framework designer support Entity Framework + BaseEntity class model? Can somebody answer the question in this thread?

http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/038d14e8-fc04-4b06-b1e4-d5b1a950a901

Thanks!

# Biju Thomas said on August 31, 2009 8:19 AM:

Hi

I want to initialize the some navigation properties to new instance when a new instance of an entity created using new operator

for eg.

I have one entity called Project wth a navigation property ApprovedBy of type 'User'. What i required is When we create  Project p = new Project() it should also initialize

   User _ApprovedBy = new User();

Now it will create only

   User ApprovedBy;

Am using Self Tracking Entities Template.

I can chage the template but it will affect all entites generated by template.

Is there is any way to initialize a navigation property by setting something like 'Initialize New Instnace' through EDM Designer ?

# Biju Thomas said on September 4, 2009 8:00 AM:

Hi am getting error

An item with the same key has already been added.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: An item with the same key has already been added.

Source Error:

Line 41: using (TContext context = new TContext())

Line 42: {

Line 43: context.ApplyChanges(this.EntitySet, entity, EntityChangeTrackerAdapter.GetSelfTrackingEntityInfo);

Line 44: context.SaveChanges(SaveOptions.DetectChangesBeforeSave);

Line 45: }

This is because i have two navigation propeties whic are pointing to same table

newRequirement.CreatedBy = new User();

newRequirement.CreatedBy.UserId = 1;

newRequirement.WorkflowUser = new User();

newRequirement.WorkflowUser.UserId = 1;

It will work wthout any issue if we comment WorkfolwUser lines

How we can solve this issue....

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

Search

This Blog

Syndication

Page view tracker