Click here to Skip to main content
15,880,608 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# Pin
OriginalGriff31-Jul-15 4:12
mveOriginalGriff31-Jul-15 4:12 
AnswerRe: C# Pin
F-ES Sitecore31-Jul-15 4:13
professionalF-ES Sitecore31-Jul-15 4:13 
AnswerRe: C# Pin
Richard MacCutchan31-Jul-15 5:08
mveRichard MacCutchan31-Jul-15 5:08 
QuestionCookies Pin
Member 1073200431-Jul-15 1:50
Member 1073200431-Jul-15 1:50 
AnswerRe: Cookies Pin
Pete O'Hanlon31-Jul-15 1:55
mvePete O'Hanlon31-Jul-15 1:55 
Questionhow to pass data from gridview page to another page textbox in asp.net with C# Pin
Member 1158609831-Jul-15 0:30
Member 1158609831-Jul-15 0:30 
AnswerRe: how to pass data from gridview page to another page textbox in asp.net with C# Pin
OriginalGriff31-Jul-15 0:52
mveOriginalGriff31-Jul-15 0:52 
QuestionRecursive update of entity with Entity Framework 6 Pin
.le.m.30-Jul-15 21:45
.le.m.30-Jul-15 21:45 
Hello everyone,

I've been working on a C# project with WPF client, WCF server and Entity Framework 6 to get database access. I use an entity-object to communicate between server and client. Due to this the entity is detached from entity framework cache manager when transferred to the client. If there is an update the client calls a server facade through service references and sends the updated entity. Since it's detached a simple dbContext.SaveChanges() on server-side doesn't work, so I set
dbContext.Entry( project ).State = EntityState.Modified;
dbContext.SaveChanges();

where 'project' is my entity I want to update. This works fine on the entity itself but I need a solution to update the entity and all corresponding entities held within this entity - a recursive update.

To make it more clear have a look on the ERM. Project holds a Client and Building which are also entity-objects.
http://imageshack.com/a/img537/8806/y6Zzxt.png[^]

When I set the explicit state for each entity it works, but then again it's not as generic as I wish for. So the challange is to find a solution where I don't have to handle each property of my entity-object separately.

Currently I use the repository pattern as follows:
public abstract class PersistenceIntegrationService<T> : IPersistenceIntegrationService<T> where T : BaseEntity
{
  ...

  public T Update( T entity )
  {
    if ( entity == null )
    {
      throw new ArgumentNullException( "entity" );
    }

    try
    {
      this.PreUpdate( entity ); // pre-update-hook

      this.AddModifyInformation( entity ); // set ModifiedOn and ModifiedBy properties
      this.persistenceContext.SetModified( entity ); // calls dbContext.Entry( project ).State = EntityState.Modified;
      this.persistenceContext.SaveChanges();

      this.PostUpdate( entity ); // post-update-hook
    }
    catch ( DbEntityValidationException e )
    {
      string message = this.PrettifyDbEntityValidationExceptionMessage( e );
      throw new EntityValidationException( message, e );
    }
    return entity;
  }
}

Although I have pre-persist-hooks I do not want to set the state explicitly, as mentioned earlier. I wonder if there is a built-in solution from entity framework. For my searches on the web I didn't find any hints regarding this challange.

I would appreciate any suggestion or idea.

modified 3-Aug-15 4:27am.

AnswerRe: Reursive update of entity with Entity Framework 6 Pin
Gerry Schmitz31-Jul-15 10:33
mveGerry Schmitz31-Jul-15 10:33 
GeneralRe: Reursive update of entity with Entity Framework 6 Pin
.le.m.2-Aug-15 22:26
.le.m.2-Aug-15 22:26 
GeneralRe: Reursive update of entity with Entity Framework 6 Pin
Gerry Schmitz3-Aug-15 10:46
mveGerry Schmitz3-Aug-15 10:46 
Questionseparating axis theorem Pin
Isawyouoo30-Jul-15 11:59
Isawyouoo30-Jul-15 11:59 
AnswerRe: separating axis theorem Pin
Dave Kreskowiak30-Jul-15 14:23
mveDave Kreskowiak30-Jul-15 14:23 
GeneralRe: separating axis theorem Pin
Isawyouoo30-Jul-15 15:04
Isawyouoo30-Jul-15 15:04 
QuestionQR code encoder and decoder Pin
Pai Soe30-Jul-15 7:53
Pai Soe30-Jul-15 7:53 
AnswerRe: QR code encoder and decoder Pin
RedDk30-Jul-15 8:08
RedDk30-Jul-15 8:08 
QuestionJava Pin
jubayer30-Jul-15 0:27
jubayer30-Jul-15 0:27 
AnswerRe: Java Pin
CHill6030-Jul-15 0:39
mveCHill6030-Jul-15 0:39 
QuestionC# Guinea Pig Needed PinPopular
.dan.g.29-Jul-15 14:36
professional.dan.g.29-Jul-15 14:36 
AnswerRe: C# Guinea Pig Needed Pin
Manfred Rudolf Bihy30-Jul-15 1:35
professionalManfred Rudolf Bihy30-Jul-15 1:35 
GeneralRe: C# Guinea Pig Needed Pin
Pete O'Hanlon30-Jul-15 2:21
mvePete O'Hanlon30-Jul-15 2:21 
GeneralRe: C# Guinea Pig Needed Pin
.dan.g.30-Jul-15 2:41
professional.dan.g.30-Jul-15 2:41 
GeneralRe: C# Guinea Pig Needed Pin
Manfred Rudolf Bihy30-Jul-15 2:46
professionalManfred Rudolf Bihy30-Jul-15 2:46 
GeneralRe: C# Guinea Pig Needed Pin
.dan.g.30-Jul-15 2:49
professional.dan.g.30-Jul-15 2:49 
GeneralRe: C# Guinea Pig Needed Pin
Maciej Los30-Jul-15 3:00
mveMaciej Los30-Jul-15 3:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.