Achievements for Visual Studio 2010

Sorry, this entry is only available in Deutsch.

Sorry, this entry is only available in Deutsch.

Authorisation check via enumerations

Sorry, this entry is only available in Deutsch.

In my current project, called Studentenverwaltungsprojekt, I use the Entity Framework for querying data from the database and submitting back again. Because my clientapplication is not bound to the database ( using services ! ) all the time I was forced to create ‘businessobjects‘ that are (nearly) stateless for communication. Today I needed to find a way to submit changes to the datasource from within theses businessobjects in the most simple and performant way.

Luckily I designed my businessobjects so that a copy of a detached EF Entity was the base of these businessobjects. At first I tried to use the function ’Context.Attach( obj );‘  which sadly didn’t commit any changes.

A few moments of gathering informations via google I found a solution that worked for me :


using ( var context = new EntityContext( connectionstring ) )
{
   if ( detachedObject.EntityState == EntityState.Detached )
   {
      object original = null;
      if ( context.TryGetObjectByKey( detachedObject.EntityKey, out original ) )
      {
         context.ApplyCurrentValues<T>( context.T.EntitySet.Name, detachedObject );
      }
   }
}

I will write more about the structure of my businessobjects in the near future


 

Sorry, this entry is only available in Deutsch.