Re: [Firebird-net-provider] Handling Errors with EF

2017-08-01 Thread Jiří Činčura
> Stacktrace of the inner exception:
> 
>bei
>System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
>bei
>
> System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.b__2(UpdateTranslator
>ut)
>bei
>System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update[T](T
>noChangesResult, Func`2 updateFunction)
>bei
>System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update()
>bei
>System.Data.Entity.Core.Objects.ObjectContext.b__35()
>bei
>
> System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1
>func, IDbExecutionStrategy executionStrategy, Boolean
>startLocalTransaction, Boolean releaseConnectionOnSuccess)
>bei
>
> System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions
>options, IDbExecutionStrategy executionStrategy, Boolean
>startLocalTransaction)
>bei
>
> System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass2a.b__27()
>bei
>
> System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func`1
>operation)
>bei
>
> System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions
>options, Boolean executeInExistingTransaction)
>bei
>System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions
>options)
>bei System.Data.Entity.Internal.InternalContext.SaveChanges()

This is from SaveChanges. It's not related to setting state to Detached.

-- 
Mgr. Jiří Činčura
https://www.tabsoverspaces.com/

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider


Re: [Firebird-net-provider] Handling Errors with EF

2017-08-01 Thread Nikolaus Kern
Hello,

this is the current config:

ctx.Configuration.ProxyCreationEnabled = false;

// res is the main object = an employee
// res.ARBEITSZEITEN are the list of past and current engagements

res = ctx.RESSOURCEN.Include(z => z.ARBEITSZEITEN).FirstOrDefault(a => 
a.EXTERNE_ID == personalnummer);
// In the case of an error:
foreach (ARBEITSZEITEN a in res.ARBEITSZEITEN)
{
ctx.Entry(a).State = EntityState.Detached;
}
ctx.Entry(res).State = EntityState.Detached;

Stacktrace of the inner exception:

   bei System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
   bei 
System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.b__2(UpdateTranslator
 ut)
   bei System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update[T](T 
noChangesResult, Func`2 updateFunction)
   bei System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update()
   bei System.Data.Entity.Core.Objects.ObjectContext.b__35()
   bei 
System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 
func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, 
Boolean releaseConnectionOnSuccess)
   bei 
System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions 
options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction)
   bei 
System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass2a.b__27()
   bei 
System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func`1
 operation)
   bei 
System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions 
options, Boolean executeInExistingTransaction)
   bei System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions 
options)
   bei System.Data.Entity.Internal.InternalContext.SaveChanges()


Thanks

Niko

-Ursprüngliche Nachricht-
Von: Jiří Činčura [mailto:j...@cincura.net] 
Gesendet: Dienstag, 1. August 2017 11:52
An: firebird-net-provider@lists.sourceforge.net
Betreff: Re: [Firebird-net-provider] Handling Errors with EF

> If I want to loop through the navigation property directy (without 
> copying it to another List) is there a way to do this? I don#t 
> understand the collection changed error, because I do not add or 
> remove an item from the list. I am changing the Entitystate.

What's the exception stack trace? That should work out of the box (with the 
proxies turned off).

--
Mgr. Jiří Činčura
https://www.tabsoverspaces.com/

--
Check out the vibrant tech community on one of the world's most engaging tech 
sites, Slashdot.org! http://sdm.link/slashdot 
___
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider


Re: [Firebird-net-provider] Handling Errors with EF

2017-08-01 Thread Jiří Činčura
> If I want to loop through the navigation property directy (without
> copying it to another List) is there a way to do this? I don#t
> understand the collection changed error, because I do not add or remove
> an item from the list. I am changing the Entitystate.

What's the exception stack trace? That should work out of the box (with
the proxies turned off).

-- 
Mgr. Jiří Činčura
https://www.tabsoverspaces.com/

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider


Re: [Firebird-net-provider] Handling Errors with EF

2017-08-01 Thread Nikolaus Kern
Hello Jiri,

thanks for the fast response.

If I want to loop through the navigation property directy (without copying it 
to another List) is there a way to do this? I don#t understand the 
collection changed error, because I do not add or remove an item from the list. 
I am changing the Entitystate.

foreach (BAU2ORG bau2org in this.NeueBaustelle.BAU2ORG)
{
 this._ctx.Entry(bau2org).State = EntityState.Detached;
}

Niko

-Ursprüngliche Nachricht-
Von: Jiří Činčura [mailto:j...@cincura.net] 
Gesendet: Dienstag, 1. August 2017 11:15
An: firebird-net-provider@lists.sourceforge.net
Betreff: Re: [Firebird-net-provider] Handling Errors with EF

> I would like to understand if there is a better way to handle the 
> relation between the main entitiy and navigation properties when a
> SaveChanges() fails.

It's generally expected that every change in DbContext (and hence in
UOW) will be saved. The user will eventually fix all validation violations. 
Hence the skipping is kind of non-standard scenario.
Detaching the graph is then correct solution. Sadly you have to detach the 
whole graph manually 
(https://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.detach(v=vs.110).aspx).
Given the DbContext is the UOW these no way to disconnect these - have one 
DbContext with multiple UOWs (where you'd discard that UOW with violations and 
continue saving). Or course poor man's solution would be to create bunch of 
DbContexts, but I'm afraid that would hurt performance and add complexity on 
the other side with attaching.

--
Mgr. Jiří Činčura
https://www.tabsoverspaces.com/

--
Check out the vibrant tech community on one of the world's most engaging tech 
sites, Slashdot.org! http://sdm.link/slashdot 
___
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider


Re: [Firebird-net-provider] Handling Errors with EF

2017-08-01 Thread Jiří Činčura
> I would like to understand if there is a better way to handle the
> relation between the main entitiy and navigation properties when a
> SaveChanges() fails.

It's generally expected that every change in DbContext (and hence in
UOW) will be saved. The user will eventually fix all validation
violations. Hence the skipping is kind of non-standard scenario.
Detaching the graph is then correct solution. Sadly you have to detach
the whole graph manually
(https://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.detach(v=vs.110).aspx).
Given the DbContext is the UOW these no way to disconnect these - have
one DbContext with multiple UOWs (where you'd discard that UOW with
violations and continue saving). Or course poor man's solution would be
to create bunch of DbContexts, but I'm afraid that would hurt
performance and add complexity on the other side with attaching.

-- 
Mgr. Jiří Činčura
https://www.tabsoverspaces.com/

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider


Re: [Firebird-net-provider] Handling Errors with EF

2017-08-01 Thread Nikolaus Kern
Hello Jiri,

by gentle way I mean that one failing record does not impact the following 
context.SaveChanges(). 

Yes I want to skip the failing record. If the user complets e.g. missing data 
and submits the data a second time I will add the entity again and save it. 
During a mass import of data I also want to skip the failing record and 
continue.

Regarding proxy creation: It was enabled at the beginning, I disabled it, but 
did not see a difference.

This approach is currently working for me:

// Copy alle records of the relevant navigation property to a new list.
Arbeitszeiten.AddRange(res.ARBEITSZEITEN);

// ctx.SaveChanges() fails

foreach (ARBEITSZEITEN a in Arbeitszeiten)
{
ctx.Entry(a).State = EntityState.Detached;
}

ctx.Entry(res).State = EntityState.Detached;

I would like to understand if there is a better way to handle the relation 
between the main entitiy and navigation properties when a SaveChanges() fails.

Niko

-Ursprüngliche Nachricht-
Von: Jiří Činčura [mailto:j...@cincura.net] 
Gesendet: Montag, 31. Juli 2017 16:09
An: firebird-net-provider@lists.sourceforge.net
Betreff: Re: [Firebird-net-provider] Handling Errors with EF

What do you mean by "gentle way". You want to skip that record? Or skip all 
pending changes?

Also do you have proxy creation enabled?

--
Mgr. Jiří Činčura
https://www.tabsoverspaces.com/


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider


Re: [Firebird-net-provider] Handling Errors with EF

2017-07-31 Thread Jiří Činčura
What do you mean by "gentle way". You want to skip that record? Or skip
all pending changes?

Also do you have proxy creation enabled?

-- 
Mgr. Jiří Činčura
https://www.tabsoverspaces.com/


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider