Quantcast
Channel: Entity Framework
Viewing all 10318 articles
Browse latest View live

Commented Feature: Reverse engineering does not mark GUID keys with default NEWSEQUENTIALID() as store generated identities [6]

$
0
0
When a table has a key column of type uniqueidentifier with a default value of newsequentialid() EF (both the Database First and the Reverse Engineer Code First in the PowerTools) should understand that this field is a StoreGeneratedPattern="Identity".

[Repro]
See attached file for a table definition that uses a uniqueidentifier with default value newsequentialid().

[Expected]
Reverse Engineer Code First, or the regular Database First (EDMX) workflow, should mark the key property as StoreGeneratedPattern="Identity". For example, the SSDL should look like this:
<Property Name="PersonID" Type="uniqueidentifier" Nullable="false" StoreGeneratedPattern="Identity" />

[Actual]
The StoreGeneratedPattern="Identity" is not being generated for GUID properties in this scenario.
Comments: I would like to know which version future refers to as it was very annoying when I found this bug. Also it has been over 2 years since this has been reported.

Source code checked in, #6eaf2b720a72880977631cba67ff334900c4c9e6

$
0
0
Careful! Don't fall into the stream... (2468: DatabaseLogger throws System.ArgumentOutOfRangeException) DatabaseLogger has a mode where it writes to a file using a StreamWriter. This can be used by multiple threads concurrently, but the StreamWriter is not thread safe. This change locks while doing the writes to prevent concurrency issues.

Source code checked in, #607ec1fc77eafd2e9d17eee6471634d338564ccc

$
0
0
Foot in the door... (2447: Need a public method in DbModelBuilder) This change creates a public non-generic method for registering entity types on DbModelBuilder. It does not allow further configuration of the entity type since this would require quite extensive changes to the fluent API surface which is heavily based on generics. However, these is still some value to this method because it is not uncommon to want to register types dynamically and then have the model configured by conventions--for example, this is what DbContext does by default. EF7 will allow full configuration without using generics. I gave this method a different name than the current internal method since I know a fair amount of code already accesses that method using Reflection. The return type of the public method is void and both making the internal method public and changing its return type could cause Reflection code to break.

Commented Feature: Need a public method in DbModelBuilder [2447]

$
0
0
need a public method in DbModelBuilder

public virtual EntityTypeConfiguration Entity(Type type) {};

so we can use like this

foreach (var entityType in entityTypeList)
{
dbmodelBuilder.Entity(type);
}

Although we can use EntityTypeConfiguration and Flunet api to generate DbContext, we want to use entity
class to generate DbContext becouse of OO conception.
Comments: Fixed in https://entityframework.codeplex.com/SourceControl/changeset/607ec1fc77eafd2e9d17eee6471634d338564ccc Foot in the door... (2447: Need a public method in DbModelBuilder) This change creates a public non-generic method for registering entity types on DbModelBuilder. It does not allow further configuration of the entity type since this would require quite extensive changes to the fluent API surface which is heavily based on generics. However, these is still some value to this method because it is not uncommon to want to register types dynamically and then have the model configured by conventions--for example, this is what DbContext does by default. EF7 will allow full configuration without using generics. I gave this method a different name than the current internal method since I know a fair amount of code already accesses that method using Reflection. The return type of the public method is void and both making the internal method public and changing its return type could cause Reflection code to break.

Edited Feature: Need a public method in DbModelBuilder [2447]

$
0
0
need a public method in DbModelBuilder

public virtual EntityTypeConfiguration Entity(Type type) {};

so we can use like this

foreach (var entityType in entityTypeList)
{
dbmodelBuilder.Entity(type);
}

Although we can use EntityTypeConfiguration and Flunet api to generate DbContext, we want to use entity
class to generate DbContext becouse of OO conception.

Edited Issue: DatabaseLogger throws System.ArgumentOutOfRangeException [2468]

$
0
0
Can you please make a Thread safe StreamWriter?

System.ArgumentOutOfRangeException
Message Count cannot be less than zero. Parameter name: count
Source mscorlib
TargetSite Void CopyTo(Int32, Char[], Int32, Int32)
StackTrace at System.String.CopyTo(Int32 sourceIndex, Char[] destination, Int32 destinationIndex, Int32 count) at System.IO.StreamWriter.Write(String value) at System.Data.Entity.Infrastructure.Interception.DatabaseLogFormatter.Opened(DbConnection connection, DbConnectionInterceptionContext interceptionContext) at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.<>c__DisplayClass3`2.<DispatchAsync>b__2(Task t) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass4.<<ExecuteAsync>b__3>d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<ExecuteAsyncImplementation>d__9`1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Data.Entity.Core.EntityClient.EntityConnection.<OpenAsync>d__8.MoveNext


Env:
EntityFramework version="6.1.1"

<interceptors>
<interceptor type="System.Data.Entity.Infrastructure.Interception.DatabaseLogger, EntityFramework">
<parameters>
<parameter value="D:\Logs\LogOutput.txt"/>
</parameters>
</interceptor>
</interceptors>


Commented Issue: DatabaseLogger throws System.ArgumentOutOfRangeException [2468]

$
0
0
Can you please make a Thread safe StreamWriter?

System.ArgumentOutOfRangeException
Message Count cannot be less than zero. Parameter name: count
Source mscorlib
TargetSite Void CopyTo(Int32, Char[], Int32, Int32)
StackTrace at System.String.CopyTo(Int32 sourceIndex, Char[] destination, Int32 destinationIndex, Int32 count) at System.IO.StreamWriter.Write(String value) at System.Data.Entity.Infrastructure.Interception.DatabaseLogFormatter.Opened(DbConnection connection, DbConnectionInterceptionContext interceptionContext) at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.<>c__DisplayClass3`2.<DispatchAsync>b__2(Task t) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass4.<<ExecuteAsync>b__3>d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<ExecuteAsyncImplementation>d__9`1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Data.Entity.Core.EntityClient.EntityConnection.<OpenAsync>d__8.MoveNext


Env:
EntityFramework version="6.1.1"

<interceptors>
<interceptor type="System.Data.Entity.Infrastructure.Interception.DatabaseLogger, EntityFramework">
<parameters>
<parameter value="D:\Logs\LogOutput.txt"/>
</parameters>
</interceptor>
</interceptors>


Comments: Fixed in https://entityframework.codeplex.com/SourceControl/changeset/6eaf2b720a72880977631cba67ff334900c4c9e6 Careful! Don't fall into the stream... (2468: DatabaseLogger throws System.ArgumentOutOfRangeException) DatabaseLogger has a mode where it writes to a file using a StreamWriter. This can be used by multiple threads concurrently, but the StreamWriter is not thread safe. This change locks while doing the writes to prevent concurrency issues.

Commented Feature: Need a public method in DbModelBuilder [2447]

$
0
0
need a public method in DbModelBuilder

public virtual EntityTypeConfiguration Entity(Type type) {};

so we can use like this

foreach (var entityType in entityTypeList)
{
dbmodelBuilder.Entity(type);
}

Although we can use EntityTypeConfiguration and Flunet api to generate DbContext, we want to use entity
class to generate DbContext becouse of OO conception.
Comments: Thanks for you replay and works!

Commented Unassigned: Issue with navigation properties & entity splitting [2465]

$
0
0
Starting with Entity Framework 6.1.1, an argument exception is raised for navigation properties when using entity splitting. Interestingly, this only occurs when more than 2 tables are mapped to one entity.

```
public class Customer
{
public int CompanyNumber { get; set; }

public bool Active { get; set; }

public int PaymentTermsNumber { get; set; }

public string LabelNotes { get; set; }

public int FreightTermsNumber { get; set; }

public virtual PaymentTerms PaymentTerms { get; set; }

public virtual FreightTerms FreightTerms { get; set; }


public class EntityTypeConfiguration : EntityTypeConfiguration<Customer>
{
public EntityTypeConfiguration()
{
Property(p => p.CompanyNumber).HasColumnName("COMPANY_NO");

HasKey(k => k.CompanyNumber);

Map(m =>
{
m.Property(p => p.Active).HasColumnName("ACTIVE_FL");
m.ToTable("F_CUSTOMER", "GLOBAL");
});

// No exception will be raised for the first or second table referenced (i.e. FreightTerms)
Map(m =>
{
m.Property(p => p.LabelNotes).HasColumnName("LABEL_NOTES");
m.Property(p => p.FreightTermsNumber).HasColumnName("FREIGHT_TERM_NO");
m.ToTable("F_CUSTOMER_PREFS", "GLOBAL");
});

// System.ArgumentException: The item with identity 'Customer_PaymentTerms1' already exists in the metadata collection.
Map(m =>
{
m.Property(p => p.PaymentTermsNumber).HasColumnName("PAYMENT_TERM_NO");
m.ToTable("F_CUSTOMER_CREDIT", "GLOBAL");
});

HasRequired(p => p.FreightTerms).WithMany().HasForeignKey(p => p.FreightTermsNumber);
HasRequired(p => p.PaymentTerms).WithMany().HasForeignKey(p => p.PaymentTermsNumber);
}
}
}
```

```
System.ArgumentException was unhandled
HResult=-2147024809
Message=The item with identity 'Customer_PaymentTerms1' already exists in the metadata collection.
Parameter name: item
Source=EntityFramework
ParamName=item
StackTrace:
at System.Data.Entity.Core.Metadata.Edm.MetadataCollection`1.AddInternal(T item)
at System.Data.Entity.Core.Metadata.Edm.MetadataCollection`1.Add(T item)
at System.Data.Entity.Core.Metadata.Edm.EntitySetBaseCollection.Add(EntitySetBase item)
at System.Data.Entity.Core.Metadata.Edm.EntityContainer.AddEntitySetBase(EntitySetBase entitySetBase)
at System.Data.Entity.ModelConfiguration.Edm.EdmModelExtensions.AddAssociationSet(EdmModel model, AssociationSet associationSet)
at System.Data.Entity.Core.Metadata.Edm.ForeignKeyBuilder.SetOwner(EntityType owner)
at System.Data.Entity.Core.Metadata.Edm.EntityType.AddForeignKey(ForeignKeyBuilder foreignKeyBuilder)
at System.Data.Entity.ModelConfiguration.Configuration.Mapping.ForeignKeyPrimitiveOperations.CopyForeignKeyConstraint(EdmModel database, EntityType toTable, ForeignKeyBuilder fk, Func`2 selector)
at System.Data.Entity.ModelConfiguration.Configuration.Mapping.ForeignKeyPrimitiveOperations.<>c__DisplayClass39.<CopyAllForeignKeyConstraintsForColumn>b__37(ForeignKeyBuilder fk)
at System.Data.Entity.Utilities.IEnumerableExtensions.Each[T](IEnumerable`1 ts, Action`1 action)
at System.Data.Entity.ModelConfiguration.Configuration.Mapping.ForeignKeyPrimitiveOperations.CopyAllForeignKeyConstraintsForColumn(EdmModel database, EntityType fromTable, EntityType toTable, EdmProperty column, EdmProperty movedColumn)
at System.Data.Entity.ModelConfiguration.Configuration.Mapping.TableOperations.CopyColumnAndAnyConstraints(EdmModel database, EntityType fromTable, EntityType toTable, EdmProperty column, Func`2 isCompatible, Boolean useExisting)
at System.Data.Entity.ModelConfiguration.Configuration.Mapping.EntityMappingOperations.UpdatePropertyMapping(EdmModel database, Dictionary`2 columnMappingIndex, ColumnMappingBuilder propertyMappingBuilder, EntityType fromTable, EntityType toTable, Boolean useExisting)
at System.Data.Entity.ModelConfiguration.Configuration.Mapping.EntityMappingOperations.MovePropertyMapping(DbDatabaseMapping databaseMapping, MappingFragment fromFragment, MappingFragment toFragment, ColumnMappingBuilder propertyMappingBuilder, Boolean requiresUpdate, Boolean useExisting)
at System.Data.Entity.ModelConfiguration.Configuration.Mapping.EntityMappingConfiguration.Configure(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest, EntityType entityType, EntityTypeMapping& entityTypeMapping, Boolean isMappingAnyInheritedProperty, Int32 configurationIndex, Int32 configurationCount, IDictionary`2 commonAnnotations)
at System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.ConfigureTablesAndConditions(EntityTypeMapping entityTypeMapping, DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest)
at System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.ConfigureEntityTypes(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest)
at System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.Configure(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest)
at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.InternalContext.Initialize()
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
at System.Data.Entity.Internal.Linq.InternalSet`1.Find(Object[] keyValues)
at System.Data.Entity.DbSet`1.Find(Object[] keyValues)
at IsolateCustomerEFIssue.Form1.timer1_Tick(Object sender, EventArgs e)
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at IsolateCustomerEFIssue.Program.Main()
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
```
Comments: If I am not mistaken it started happening after this: 7bbd3a57f40638b7e3955e3df40fe914eff19c26 - Fix for #2103 - Add-migration fails after creating TPT schema At first glance the SetPreferredName call seems to interfere with the name uniquification.

Created Unassigned: SQL error when migrating down [2483]

$
0
0
Repro steps:
1. Create an entity with a DateTime column that is required, and add a migration for it.
2. Change the column type to smalldatetime, and add a migration for it.
3. Drop the column, and add a migration for it.

Running a full Update-Database on an empty database, then an Update-Database -TargetMigration 0 results in an error:

> Msg 5074, Level 16, State 1, Line 4
The object 'DF__MyEntity__Someth__1273C1CD' is dependent on column 'Something'.
Msg 4922, Level 16, State 9, Line 4
ALTER TABLE ALTER COLUMN Something failed because one or more objects access this column.

In the attachment you will find:
* The complete source code with the three different mappings and three migrations v1-v2-v3
* migr_up.sql which is generated by Update-Database on an empty database
* migr_down.sql which is generated by an Update-Database -TargetMigration 0

If you simply run migr_up.sql then migr_down.sql on an empty database, you will see the error.

It's not a contrived example, this sequence actually occurred in a production project.

Source code checked in, #5660d5b988d92b39d9f7a192e25dfe860f333f66

$
0
0
Bug 952621: DTS: EF creates unnecessary joins when using derived types. When the PreProcessor encounters a navigation PropertyOp it rewrites the corresponding node into one that represents a query. The query is then added as nested subquery to the first RelOp ancestor. When the RelOp nodes are processed, the SubqueryTrackingVisitor creates a chain of outer applies: if S1, S2, ... are the subqueries and D the original (driver) input, the output created looks like OuterApply(OuterApply(D, S1), S2), ... Later in the plan compiler, when the transformations are run, the outer applies are transformed into left outer joins. If a Linq query projects multiple properties of an object accessed via a navigation property (x.NavProp.P1, x.NavProp.P2, ...) the final query ends having duplicated joins. The JoinElimination phase tries to eliminated duplicates but does not cover complex cases. Instead of attempting to enhance the JoinElimination phase further, and make that code even more complex, the fix eliminates the duplicate subqueries early, in the PreProcessor, by caching and reusing the rewritten nodes. The logic for cache hits is implemented in the NavigationPropertyOpInfo class. Basically two navigation property nodes are considered equivalent from the cache point of view if they have the same RelOp ancestor (not null), same navigation property (EdmMember) and the subtrees having them as root are equivalent. For fast retrieval GetHashCode computes a hash code using the RelOp ancestor's hash code, the navigation property's hash code and the node's computed hash value.

Commented Issue: MSSQL 2014, Update model are very slow [2445]

$
0
0
Hello,

I have migrate a project from MSSQL 2012 to MSSQL 2014. I run my application and no problem, all work fine.

I'm Database first with EF. Then I add a new column in a table. Go in the EF Designer and launch "Update model from database". Now, this action take around 30 minutes (versus 1 minute with MSSQL 2012).

I create a new blank EDMX, try "Update model from database" and it's take around 30min.

My config:
Visual Studio Pro 2013 Update 3
.Net Framework 4.5.1
Entity Framework 6.1.1
MS SQL 2014

100 Tables
238 Stored procedures
Comments: @ErikEJ it's the store schema queries defined under [src/EntityFramework.SqlServer/Resources/System/Data/SqlClient](https://entityframework.codeplex.com/SourceControl/latest#src/EntityFramework.SqlServer/Resources/System/Data/SqlClient/).

Commented Unassigned: nullablewhere null [2436]

$
0
0
Hi

I have a db bigInt mapped in entity as an Int64.

If I use a previously declared nullable long variable in an entity query I do not get any results if the value of this variable is "null"

An example:
```
long? registrationNumber = null;
objectContext.Persons.Where(p => c.RegNumber == registrationNumber).Count();
```

Creates an SQL Statement with

> where pers_regnumber = NULL

As with other types like Int32 I would have expected this to create a "
> where pers_regnumber is null


As a hotfix I have used this to create a correct SQL
```
long? registrationNumber = null;
objectContext.Persons.Where(p => c.RegNumber == registrationNumber || (registrationNumber == null && c.RegNumber == null)).Count();
```
I am using EF 6.1.0.

Comments: Resolving this as By Design. Feel free to re-activate if you disagree.

Closed Unassigned: nullablewhere null [2436]

$
0
0
Hi

I have a db bigInt mapped in entity as an Int64.

If I use a previously declared nullable long variable in an entity query I do not get any results if the value of this variable is "null"

An example:
```
long? registrationNumber = null;
objectContext.Persons.Where(p => c.RegNumber == registrationNumber).Count();
```

Creates an SQL Statement with

> where pers_regnumber = NULL

As with other types like Int32 I would have expected this to create a "
> where pers_regnumber is null


As a hotfix I have used this to create a correct SQL
```
long? registrationNumber = null;
objectContext.Persons.Where(p => c.RegNumber == registrationNumber || (registrationNumber == null && c.RegNumber == null)).Count();
```
I am using EF 6.1.0.

Comments: See comments.

Commented Issue: MSSQL 2014, Update model are very slow [2445]

$
0
0
Hello,

I have migrate a project from MSSQL 2012 to MSSQL 2014. I run my application and no problem, all work fine.

I'm Database first with EF. Then I add a new column in a table. Go in the EF Designer and launch "Update model from database". Now, this action take around 30 minutes (versus 1 minute with MSSQL 2012).

I create a new blank EDMX, try "Update model from database" and it's take around 30min.

My config:
Visual Studio Pro 2013 Update 3
.Net Framework 4.5.1
Entity Framework 6.1.1
MS SQL 2014

100 Tables
238 Stored procedures
Comments: @davidobando thanks, I know. Do you know which one of them?

Edited Unassigned: Entity naming can cause parent records to be deleted before children causing reference constraint exceptions. [2431]

$
0
0
When a parent and child's DbEntityEntry.State is moved from one context to another, delete requests will fail if the parent entity's name falls before the child's alphabetically. In the attached example's "Bad" project a parent and child are removed from one context. The entities are then detached from the source context and then reattached in a second context using DbContext.Entry(), afterwhich the entity state is restored. When DbContext.SaveChanges() is called a reference constraint exception is thrown. The example contains a "Good" project with the only difference being that the child's name falls before the parents alphabetically. An exception does not occur when "Good" is run.

The expectation is the relationship between the entities should determine the order of deletion and not the alphabetical order of the parent/child names.

A workaround was found. First the target entity is pulled into the second context using DbSet.Find(). The found entity is then used to pull up the DbEntityEntry using DbContext.Entry(). The state is then set to deleted. Performing this on the parent and child results in a successful save.

This behavior was found in both EF 6.0.1 and 6.1.1.


Commented Unassigned: Entity naming can cause parent records to be deleted before children causing reference constraint exceptions. [2431]

$
0
0
When a parent and child's DbEntityEntry.State is moved from one context to another, delete requests will fail if the parent entity's name falls before the child's alphabetically. In the attached example's "Bad" project a parent and child are removed from one context. The entities are then detached from the source context and then reattached in a second context using DbContext.Entry(), afterwhich the entity state is restored. When DbContext.SaveChanges() is called a reference constraint exception is thrown. The example contains a "Good" project with the only difference being that the child's name falls before the parents alphabetically. An exception does not occur when "Good" is run.

The expectation is the relationship between the entities should determine the order of deletion and not the alphabetical order of the parent/child names.

A workaround was found. First the target entity is pulled into the second context using DbSet.Find(). The found entity is then used to pull up the DbEntityEntry using DbContext.Entry(). The state is then set to deleted. Performing this on the parent and child results in a successful save.

This behavior was found in both EF 6.0.1 and 6.1.1.


Comments: The delete and update operations also use the "OriginalValues" of the entity entries to produce store commands. To get the expected behavior these need to be preserved as well: ``` foreach (var sourceEntry in source.ChangeTracker .Entries() .Where(e => e.State != EntityState.Detached && e.State != EntityState.Unchanged)) { // Pull the entity into the target context and restore the state. var targetEntry = target.Entry(sourceEntry.Entity); targetEntry.State = sourceEntry.State; foreach (var property in sourceEntry.OriginalValues.PropertyNames) { targetEntry.OriginalValues[property] = sourceEntry.OriginalValues[property]; } sourceEntry.State = EntityState.Detached; } ```

Closed Task: Make WithCurrentCulture() public [2425]

$
0
0
It's useful when implementing EF interfaces
Comments: straightforward change, closing

Closed Task: Add errors from memory-optimized tables to SqlAzureExecutionStrategy [2458]

$
0
0
```
// retry-worthy errors on memory-optimized tables (http://msdn.microsoft.com/en-us/library/dn169141.aspx)
case 41302:
case 41305:
case 41325:
case 41301:
```
Comments: straightforward change, no tests needed, closing

Closed Feature: Need a public method in DbModelBuilder [2447]

$
0
0
need a public method in DbModelBuilder

public virtual EntityTypeConfiguration Entity(Type type) {};

so we can use like this

foreach (var entityType in entityTypeList)
{
dbmodelBuilder.Entity(type);
}

Although we can use EntityTypeConfiguration and Flunet api to generate DbContext, we want to use entity
class to generate DbContext becouse of OO conception.
Comments: straightforward change, no additional tests needed - closing
Viewing all 10318 articles
Browse latest View live




Latest Images