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

Closed Issue: Changing Identity Column Name Creates Incorrect Migration [2402]

$
0
0
Found this issue using the same models from: [2338](https://entityframework.codeplex.com/workitem/2338)

Made a slightly easier model for repro seen below.

The issue is that changing the Primary Keys name and making a new migration will create a migration that tries to add a new identity column to the table while it still has an identity column resulting in the error "Multiple identity columns specified for table '<table>'. Only one identity column per table is allowed."

First Migration used this:
```
public class CodeFirstModel
{
public int MyPrimaryKey { get; set; }
}
```

Changed to the below model and made a new migration:
```
public class CodeFirstModel
{
public int Id { get; set; }
}
```

This is the migration that causes the error:
```
public override void Up()
{
DropPrimaryKey("dbo.CodeFirstModels");
AddColumn("dbo.CodeFirstModels", "Id", c => c.Int(nullable: false, identity: true));
AddPrimaryKey("dbo.CodeFirstModels", "Id");
DropColumn("dbo.CodeFirstModels", "MyPrimaryKey");
}
```
Comments: __EF Team Triage:__ In this case you would probably just delete all the scaffolded code and swap it to a rename rather than drop/create. Given this doesn't seem like a very common case and was logged by an EF team member and not a customer we aren't going to fix (at least for now).

Edited Feature: UpForGrabs: 'EntityValidationErrors' property not inspectable in Visual Studio 2013 [2401]

$
0
0
I have an error where the message says:

A first chance exception of type 'System.Data.Entity.Validation.DbEntityValidationException' occurred in EntityFramework.dll

Additional information: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.

However when I open the "View Detail" dialog, and go to the EntityValidationErrors property all I see is a single entry of:

{System.Data.Entity.Validation.DbEntityValidationResult}

This isn't very helpful!

Would it be possible to make it so I can inspect the errors in Visual Studio?

Commented Feature: UpForGrabs: 'EntityValidationErrors' property not inspectable in Visual Studio 2013 [2401]

$
0
0
I have an error where the message says:

A first chance exception of type 'System.Data.Entity.Validation.DbEntityValidationException' occurred in EntityFramework.dll

Additional information: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.

However when I open the "View Detail" dialog, and go to the EntityValidationErrors property all I see is a single entry of:

{System.Data.Entity.Validation.DbEntityValidationResult}

This isn't very helpful!

Would it be possible to make it so I can inspect the errors in Visual Studio?
Comments: __EF Team Triage:__ Agreed with Diego, marking as up for grabs.

Edited Feature: Need Better Support for Lookup Tables [2384]

$
0
0
Here's a good article explaining why we need better support for lookup tables in Entity Framework:
http://rationalgeek.com/blog/introducing-eflookup/



Commented Feature: Need Better Support for Lookup Tables [2384]

$
0
0
Here's a good article explaining why we need better support for lookup tables in Entity Framework:
http://rationalgeek.com/blog/introducing-eflookup/



Comments: __EF Team Triage:__ Agree with Diego, moving to Future release to make sure we don't loose track of the idea.

Edited Issue: Code First Logic to create tables on empty database should work with other providers [371]

$
0
0
**EF Team Triage: We should do this as part of the provider improvement planned after EF6** http://entityframework.codeplex.com/workitem/415

In EF5 we made Code First work in scenarios in which the target database exists but the tables still need to be created. This functionality depends on a check that is implemented in the method DatabaseTableChecker.AnyModelTableExists which currently executes hardcoded SQL information schema queries for "System.Data.SqlClient" and "System.Data.SqlClientCe.4.0" but returns true for any other ADO.NET provider invariant names:

switch (providerName)
{
case "System.Data.SqlClient":
provider = new SqlPseudoProvider();
break;
case "System.Data.SqlServerCe.4.0":
provider = new SqlCePseudoProvider();
break;
default:
return true;
}

We should instead make this logic work with any provider either moving the capabilities of the pseudo provider into the actual provider model or by taking advantage of existing functionality of the Migrations Initializer or of schema discovery in the existing provider model.

Commented Issue: Code First Logic to create tables on empty database should work with other providers [371]

$
0
0
**EF Team Triage: We should do this as part of the provider improvement planned after EF6** http://entityframework.codeplex.com/workitem/415

In EF5 we made Code First work in scenarios in which the target database exists but the tables still need to be created. This functionality depends on a check that is implemented in the method DatabaseTableChecker.AnyModelTableExists which currently executes hardcoded SQL information schema queries for "System.Data.SqlClient" and "System.Data.SqlClientCe.4.0" but returns true for any other ADO.NET provider invariant names:

switch (providerName)
{
case "System.Data.SqlClient":
provider = new SqlPseudoProvider();
break;
case "System.Data.SqlServerCe.4.0":
provider = new SqlCePseudoProvider();
break;
default:
return true;
}

We should instead make this logic work with any provider either moving the capabilities of the pseudo provider into the actual provider model or by taking advantage of existing functionality of the Migrations Initializer or of schema discovery in the existing provider model.
Comments: Fixed in https://entityframework.codeplex.com/SourceControl/changeset/48e693963aa9364b4723b424d77ac12df87cf359 Playing checkers in public... (Make DatabaseTableChecker functionality public so that other providers can implement) This change makes public the DatabaseTableChecker functionality that is currently only implemented for SQL Server and SQL Server CE. There is no change to the way the functionality is implemented and no default implementation for other providers. The idea is simply to allow other providers to do what SQL Server and SQL CE currently do, if this is useful for other providers. The changes are basically: - Make public the interface implemented by providers and make it a base class - Resolve an instance of this class from DbConfiguration - Move the SQL Server and SQL CE implementations into their respective provider assemblies - Make public some methods around transactions and interception so that these methods can be used from provider assemblies - Have the SQL Server and SQL CE providers register the service in the normal way

Edited Issue: Code First Logic to create tables on empty database should work with other providers [371]

$
0
0
**EF Team Triage: We should do this as part of the provider improvement planned after EF6** http://entityframework.codeplex.com/workitem/415

In EF5 we made Code First work in scenarios in which the target database exists but the tables still need to be created. This functionality depends on a check that is implemented in the method DatabaseTableChecker.AnyModelTableExists which currently executes hardcoded SQL information schema queries for "System.Data.SqlClient" and "System.Data.SqlClientCe.4.0" but returns true for any other ADO.NET provider invariant names:

switch (providerName)
{
case "System.Data.SqlClient":
provider = new SqlPseudoProvider();
break;
case "System.Data.SqlServerCe.4.0":
provider = new SqlCePseudoProvider();
break;
default:
return true;
}

We should instead make this logic work with any provider either moving the capabilities of the pseudo provider into the actual provider model or by taking advantage of existing functionality of the Migrations Initializer or of schema discovery in the existing provider model.

Commented Unassigned: Index out of bounds error in DetectChanges (specifically, EntityEntry.cs) [2393]

$
0
0
It seems EF is throwing an out of bounds read on the following line in __EntityEntry.cs__, function __DetectChangesInProperty__:

```
var originalValue = _originalValues[originalValueIndex].OriginalValue;

//The originalValueIndex is obtained here, however this value may sometimes be -1
var originalValueIndex = FindOriginalValueIndex(member, _wrappedEntity.Entity);
```

While the values should never be -1 unless there is an error with the entity, should it not throw some kind of custom exception? This error generally pops up after 3-5 days of using the same entity context in a game server, and we're thinking is most likely due to concurrency issues.

Also, on a side note, we've been running EF in debug mode to find this error, however every time this error starts showing up, VS no longer triggers any breakpoints inside the EF source code, nor does it step into any calls to EF. We can step/breakpoint just fine before this exception occurs.
Comments: Hi Arthur, thanks for the reply, and sorry for my late reply; I've been rather busy lately. As for the error, I was wrong, it's a null pointer exception actually. I have line numbers, and they roughly match on on the EntityEntry.cs file (I only added code to throw a custom exception any time the issue happened). Here is the real exception thrown when calling SaveChanges with the publicly released EF (6.1.1) ``` EXCEPTION SAVING CHANGES #63 -> System.NullReferenceException: Object reference not set to an instance of an object. at System.Data.Entity.Core.Objects.EntityEntry.DetectChangesInProperty(Int32 ordinal, Boolean detectOnlyComplexProperties, Boolean detectOnly) at System.Data.Entity.Core.Objects.EntityEntry.DetectChangesInProperties(Boolean detectOnlyComplexProperties) at System.Data.Entity.Core.Objects.ObjectStateManager.DetectChangesInScalarAndComplexProperties(IList`1 entries) at System.Data.Entity.Core.Objects.ObjectStateManager.DetectChanges() at System.Data.Entity.Core.Objects.ObjectContext.DetectChanges() at System.Data.Entity.Internal.InternalContext.DetectChanges(Boolean force) at System.Data.Entity.Internal.InternalContext.GetStateEntries(Func`2 predicate) at System.Data.Entity.Internal.InternalContext.GetStateEntries() at System.Data.Entity.Infrastructure.DbChangeTracker.Entries() at System.Data.Entity.DbContext.GetValidationErrors() at System.Data.Entity.Internal.InternalContext.SaveChanges() at System.Data.Entity.Internal.LazyInternalContext.SaveChanges() at System.Data.Entity.DbContext.SaveChanges() at GS.Game.SaveChanges() ``` Here is the stack trace when I had the source code attached: ``` EXCEPTION SAVING CHANGES #20 -> System.Data.Entity.CustomEX: Its -1 again... at System.Data.Entity.Core.Objects.EntityEntry.DetectChangesInProperty(Int32 ordinal, Boolean detectOnlyComplexProperties, Boolean detectOnly) in c:\Users\Administrator\Documents\Projects\Project\EntityFramework\Core\Objects\EntityEntry.cs:line 1936 at System.Data.Entity.Core.Objects.EntityEntry.DetectChangesInProperties(Boolean detectOnlyComplexProperties) in c:\Users\Administrator\Documents\Projects\Project\EntityFramework\Core\Objects\EntityEntry.cs:line 1984 at System.Data.Entity.Core.Objects.ObjectStateManager.DetectChangesInScalarAndComplexProperties(IList`1 entries) in c:\Users\Administrator\Documents\Projects\Project\EntityFramework\Core\Objects\ObjectStateManager.cs:line 4003 at System.Data.Entity.Core.Objects.ObjectStateManager.DetectChanges() in c:\Users\Administrator\Documents\Projects\Project\EntityFramework\Core\Objects\ObjectStateManager.cs:line 3325 at System.Data.Entity.Core.Objects.ObjectContext.DetectChanges() in c:\Users\Administrator\Documents\Projects\Project\EntityFramework\Core\Objects\ObjectContext.cs:line 3394 at System.Data.Entity.Internal.InternalContext.DetectChanges(Boolean force) in c:\Users\Administrator\Documents\Projects\Project\EntityFramework\Internal\InternalContext.cs:line 682 at System.Data.Entity.Internal.InternalContext.GetStateEntries(Func`2 predicate) in c:\Users\Administrator\Documents\Projects\Project\EntityFramework\Internal\InternalContext.cs:line 1071 at System.Data.Entity.Internal.InternalContext.GetStateEntries() in c:\Users\Administrator\Documents\Projects\Project\EntityFramework\Internal\InternalContext.cs:line 1050 at System.Data.Entity.Infrastructure.DbChangeTracker.Entries() in c:\Users\Administrator\Documents\Projects\Project\EntityFramework\Infrastructure\DbChangeTracker.cs:line 43 at System.Data.Entity.DbContext.GetValidationErrors() in c:\Users\Administrator\Documents\Projects\Project\EntityFramework\DbContext.cs:line 410 at System.Data.Entity.Internal.InternalContext.SaveChanges() in c:\Users\Administrator\Documents\Projects\Project\EntityFramework\Internal\InternalContext.cs:line 427 at System.Data.Entity.Internal.LazyInternalContext.SaveChanges() in c:\Users\Administrator\Documents\Projects\Project\EntityFramework\Internal\LazyInternalContext.cs:line 192 at System.Data.Entity.DbContext.SaveChanges() in c:\Users\Administrator\Documents\Projects\Project\EntityFramework\DbContext.cs:line 316 at GS.Game.SaveChanges() ``` The weirder thing is, whenever this error started occurring, the VS debugger would not even step in or breakpoint inside the EF source code. I could place the break points, but it would never hit. If i tried to step into the SaveChanges function, it would just step over. Also, as I explained before, EF is being used (partially) in a multithreaded context. While all relationships are loaded/set in the Database thread,entity values (ex: ```x.SomeValue = 10```) are set in the main server thread. There are small instances where 0 or 1-1 or 1-1 relationjships (ex: ```x.SomeRel = someObj```) are set in the server thread. Lazy loading of all relationships is also done in the database thread.

Commented Unassigned: Index out of bounds error in DetectChanges (specifically, EntityEntry.cs) [2393]

$
0
0
It seems EF is throwing an out of bounds read on the following line in __EntityEntry.cs__, function __DetectChangesInProperty__:

```
var originalValue = _originalValues[originalValueIndex].OriginalValue;

//The originalValueIndex is obtained here, however this value may sometimes be -1
var originalValueIndex = FindOriginalValueIndex(member, _wrappedEntity.Entity);
```

While the values should never be -1 unless there is an error with the entity, should it not throw some kind of custom exception? This error generally pops up after 3-5 days of using the same entity context in a game server, and we're thinking is most likely due to concurrency issues.

Also, on a side note, we've been running EF in debug mode to find this error, however every time this error starts showing up, VS no longer triggers any breakpoints inside the EF source code, nor does it step into any calls to EF. We can step/breakpoint just fine before this exception occurs.
Comments: I should also mention I just found this error in the log, prior to the null pointer error ``` System.InvalidOperationException: The changes to the database were committed successfully, but an error occurred while updating the object context. The ObjectContext might be in an inconsistent state. Inner exception message: A referential integrity constraint violation occurred: The property value(s) of 'ItemAttribute.Id' on one end of a relationship do not match the property value(s) of 'Item.ItemAttributeId' on the other end. ---> System.InvalidOperationException: A referential integrity constraint violation occurred: The property value(s) of 'ItemAttribute.Id' on one end of a relationship do not match the property value(s) of 'Item.ItemAttributeId' on the other end. at System.Data.Entity.Core.Objects.DataClasses.RelatedEnd.CheckReferentialConstraintProperties(EntityEntry ownerEntry) at System.Data.Entity.Core.Objects.DataClasses.RelationshipManager.CheckReferentialConstraintProperties(EntityEntry ownerEntry) at System.Data.Entity.Core.Objects.EntityEntry.AcceptChanges() at System.Data.Entity.Core.Objects.ObjectContext.AcceptAllChanges() at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction) --- End of inner exception stack trace --- at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction) at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass2a.<SaveChangesInternal>b__27() at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation) at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction) at System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options) at System.Data.Entity.Internal.InternalContext.SaveChanges() at System.Data.Entity.Internal.LazyInternalContext.SaveChanges() at System.Data.Entity.DbContext.SaveChanges() at GS.Game.SaveChanges() ``` Here is a picture of the relationship in question: ![Image](http://puu.sh/alvLq/4838b6ae32.png) So, it seems this is where the errors started - after it failed with this exception, it kept throwing null pointer exceptions every time SaveChanges was called

Commented Unassigned: Index out of bounds error in DetectChanges (specifically, EntityEntry.cs) [2393]

$
0
0
It seems EF is throwing an out of bounds read on the following line in __EntityEntry.cs__, function __DetectChangesInProperty__:

```
var originalValue = _originalValues[originalValueIndex].OriginalValue;

//The originalValueIndex is obtained here, however this value may sometimes be -1
var originalValueIndex = FindOriginalValueIndex(member, _wrappedEntity.Entity);
```

While the values should never be -1 unless there is an error with the entity, should it not throw some kind of custom exception? This error generally pops up after 3-5 days of using the same entity context in a game server, and we're thinking is most likely due to concurrency issues.

Also, on a side note, we've been running EF in debug mode to find this error, however every time this error starts showing up, VS no longer triggers any breakpoints inside the EF source code, nor does it step into any calls to EF. We can step/breakpoint just fine before this exception occurs.
Comments: One more thing - The ItemAttributeID is the foreign key for the "BaseAttributes" relationship. I only set the value to ItemAttributeId, I never set it via BaseAttribute relationship/navigation. In fact, I load all item attributes using non-tracked context because the Attributes are read only, and it helps speed up SaveChange (which can often take up to 10-20s after game server has been running for 4-5 days) Here is the only setter used to set that value: ``` [NotMapped] public ItemAttribute Attributes { get { return _MyAttributes ?? BaseAttributes; } set { _MyAttributes = value; ItemAttributeId = value.Id; } } ```

Created Unassigned: error in DropPrimaryKey? [2404]

$
0
0
Hi all, I have this migration script with ef 6.1.1

DropPrimaryKey("dbo.Diario");
AddColumn("dbo.Diario", "CreatedAt", c => c.DateTimeOffset(nullable: false, precision: 7,
annotations: new Dictionary<string, AnnotationValues>
{
{
"ServiceTableColumn",
new AnnotationValues(oldValue: null, newValue: "CreatedAt")
},
}));
AddColumn("dbo.Diario", "Deleted", c => c.Boolean(nullable: false,
annotations: new Dictionary<string, AnnotationValues>
{
{
"ServiceTableColumn",
new AnnotationValues(oldValue: null, newValue: "Deleted")
},
}));
AddColumn("dbo.Diario", "Id", c => c.String(maxLength: 36,
annotations: new Dictionary<string, AnnotationValues>
{
{
"ServiceTableColumn",
new AnnotationValues(oldValue: null, newValue: "Id")
},
}));
AddColumn("dbo.Diario", "UpdatedAt", c => c.DateTimeOffset(precision: 7,
annotations: new Dictionary<string, AnnotationValues>
{
{
"ServiceTableColumn",
new AnnotationValues(oldValue: null, newValue: "UpdatedAt")
},
}));
AddColumn("dbo.Diario", "Version", c => c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion",
annotations: new Dictionary<string, AnnotationValues>
{
{
"ServiceTableColumn",
new AnnotationValues(oldValue: null, newValue: "Version")
},
}));
AlterColumn("dbo.Diario", "DiarioNo", c => c.Int(nullable: false));
AddPrimaryKey("dbo.Diario", "DiarioNo");
CreateIndex("dbo.Diario", "CreatedAt", clustered: true);
CreateIndex("dbo.Diario", "Id");

Using Update_Database it I obtain this error

ALTER TABLE [dbo].[Diario] DROP CONSTRAINT [PK_dbo.Diario]

Using Update-Database -Script I obtain

ALTER TABLE [dbo].[Diario] DROP CONSTRAINT [PK_dbo.Diario]
ALTER TABLE [dbo].[Diario] ADD [CreatedAt] [datetimeoffset](7) NOT NULL DEFAULT '0001-01-01T00:00:00.000+00:00'
ALTER TABLE [dbo].[Diario] ADD [Deleted] [bit] NOT NULL DEFAULT 0
ALTER TABLE [dbo].[Diario] ADD [Id] [nvarchar](36)
ALTER TABLE [dbo].[Diario] ADD [UpdatedAt] [datetimeoffset](7)
ALTER TABLE [dbo].[Diario] ADD [Version] rowversion NOT NULL
ALTER TABLE [dbo].[Diario] ALTER COLUMN [DiarioNo] [int] NOT NULL
ALTER TABLE [dbo].[Diario] ADD CONSTRAINT [PK_dbo.Diario] PRIMARY KEY ([DiarioNo])
CREATE CLUSTERED INDEX [IX_CreatedAt] ON [dbo].[Diario]([CreatedAt])
CREATE INDEX [IX_Id] ON [dbo].[Diario]([Id])
INSERT [dbo].[__MigrationHistory]([MigrationId], [ContextKey], [Model], [ProductVersion])
VALUES (N'201407191920555_dati tabella diario', N'attivitamobileService.Migrations.Configuration', 0x1F8B08000000...

Looks like we have a strange behavior in the DropPrimaryKey("dbo.Diario"), because generates
ALTER TABLE [dbo].[Diario] DROP CONSTRAINT [PK_dbo.Diario]
instead of
ALTER TABLE [dbo].[Diario] DROP CONSTRAINT [PK_Diario]

and in
AddPrimaryKey("dbo.Diario", "DiarioNo"), because generates
ALTER TABLE [dbo].[Diario] ADD CONSTRAINT [PK_dbo.Diario] PRIMARY KEY ([DiarioNo])
instead of
ALTER TABLE [dbo].[Diario] ADD CONSTRAINT [PK_Diario] PRIMARY KEY ([DiarioNo])

btw: it's normal there is no reference to the generation of the annotations?

Created Unassigned: Wrong foreign key transcription [2405]

$
0
0
I have a strange issue with this message when saving a new created entity :

_An error occurred while saving entities that do not expose foreign key properties for their relationships. The EntityEntries property will return null because a single entity cannot be identified as the source of the exception. Handling of exceptions while saving can be made easier by exposing foreign key properties in your entity types. See the InnerException for details._

the Inner Exception says : _Invalid column name : 'Concern_Id'._

The stack trace is :
```
à System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
à System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<Update>b__2(UpdateTranslator ut)
à System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update[T](T noChangesResult, Func`2 updateFunction)
à System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update()
à System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__35()
à System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
à System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction)
à System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass2a.<SaveChangesInternal>b__27()
à System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
à System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction)
à System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options)
à System.Data.Entity.Internal.InternalContext.SaveChanges()
```
When tracing SQL Query, EF wants to add a new column with his convention in target table :

exec sp_executesql N'INSERT [dbo].[TodoList]([Code], [__ConcernId__], [Id], [__Concern_Id__])
VALUES (@0, @1, @2, @3)
',N'@0 nvarchar(50),@1 bigint,@2 bigint,@3 bigint',@0=N'TEST2',@1=75,@2=19,@3=75

The mapping of the foreign key is done in fluent like this :
```Property(p => p.ConcernId)
.HasColumnName("ConcernId")
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None)
.IsRequired();
```
And the relation is declared like this :
```
.HasRequired(t => t.Concern)
.WithMany()
.HasForeignKey(t => t.ConcernId)

```
Any idea on what happen ?
The only workaround I found is to create this additional column "Concern_Id" in DB.

Created Unassigned: Navigation property does not load with data from memory [2408]

$
0
0
Hello,

I believe this is an issue, so, the problem looks like this:

I add a new entity in the DBContext, that entity should be a navigation property to a certain instance, the problem is that the navigation property is not loaded with data from the memory, only from database.

It would be useful to force somehow the reloading of the navigation property, and not only from DB.

Regards,
Bogdan.

Edited Unassigned: Navigation property does not load with data from memory [2408]

$
0
0
Hello,

I believe this is an issue, so, the problem looks like this:

I add a new entity in the DBContext, that entity should be a navigation property to a certain instance, the problem is that the navigation property is not loaded with data from the memory, only from database.

It would be useful to force somehow the reloading of the navigation property, and not only from DB.

You can see the bug/"enhancement request" being reproduced in project found in the attached archive.

Regards,
Bogdan.

Edited Unassigned: Navigation property does not load with data from memory [2408]

$
0
0
Hello,

I believe this is an issue, so, the problem looks like this:

I add a new entity in the DBContext, that entity should be a navigation property to a certain instance, the problem is that the navigation property is not loaded with data from the memory, only from database.

It would be useful to force somehow the reloading of the navigation property, and not only from DB.

You can see the bug/"enhancement request" being reproduced in project found in the attached archive.

Regards,
Bogdan.

Edited Unassigned: Navigation property does not load data from memory [2408]

$
0
0
Hello,

I believe this is an issue, so, the problem looks like this:

I add a new entity in the DBContext, that entity should be a navigation property to a certain instance, the problem is that the navigation property is not loaded with data from the memory, only from database.

It would be useful to force somehow the reloading of the navigation property, and not only from DB.

You can see the bug/"enhancement request" being reproduced in project found in the attached archive.

Regards,
Bogdan.

New Comment on "Interception"

$
0
0
Has anyone seen a *complete* example on implementing interception for EF 6?

Commented Issue: Renaming an .edmx file doesn't rename the dependent .tt files [523]

$
0
0
Repro steps:
1. Create a project
2. Add a new .edmx ("Model1") into the project folder
3. Add an entity ("Bike") and save.
4. Rename the .edmx ("Model1") to a different name ("BikesAreAwesome").

Expected:
1) All dependent files renamed to new name, for example:
BikesAreAwesome.edmx
- BikesAreAwesome.Designer.cs
- BikesAreAwesome.edmx.diagram
- BikesAreAwesome.Context.tt
- BikesAreAwesome.tt
2) The reference to the inputFile inside the .tt files is also updated, for example:
const string inputFile = @"BikesAreAwesome.edmx";

Actual:
1) The .tt files are not renamed, for example:
BikesAreAwesome.edmx
- BikesAreAwesome.Designer.cs
- BikesAreAwesome.edmx.diagram
- Model1.Context.tt
- Model1.tt
2) The reference to the inputFile inside the .tt files is not being updated, for example:
const string inputFile = @"Model1.edmx";

No workarounds available. User has to manually rename the .tt files and edit the inputFile string.
Comments: Agree with RoMiller. If rename would cause generator and context update to break, there should be at least a warning to alert user. I tripped on this issue too and wondered why the update from database failed to reflect any changes from designer to classes.

Commented Unassigned: Wrong foreign key transcription [2405]

$
0
0
I have a strange issue with this message when saving a new created entity :

_An error occurred while saving entities that do not expose foreign key properties for their relationships. The EntityEntries property will return null because a single entity cannot be identified as the source of the exception. Handling of exceptions while saving can be made easier by exposing foreign key properties in your entity types. See the InnerException for details._

the Inner Exception says : _Invalid column name : 'Concern_Id'._

The stack trace is :
```
à System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
à System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<Update>b__2(UpdateTranslator ut)
à System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update[T](T noChangesResult, Func`2 updateFunction)
à System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update()
à System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__35()
à System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
à System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction)
à System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass2a.<SaveChangesInternal>b__27()
à System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
à System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction)
à System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options)
à System.Data.Entity.Internal.InternalContext.SaveChanges()
```
When tracing SQL Query, EF wants to add a new column with his convention in target table :

exec sp_executesql N'INSERT [dbo].[TodoList]([Code], [__ConcernId__], [Id], [__Concern_Id__])
VALUES (@0, @1, @2, @3)
',N'@0 nvarchar(50),@1 bigint,@2 bigint,@3 bigint',@0=N'TEST2',@1=75,@2=19,@3=75

The mapping of the foreign key is done in fluent like this :
```Property(p => p.ConcernId)
.HasColumnName("ConcernId")
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None)
.IsRequired();
```
And the relation is declared like this :
```
.HasRequired(t => t.Concern)
.WithMany()
.HasForeignKey(t => t.ConcernId)

```
Any idea on what happen ?
The only workaround I found is to create this additional column "Concern_Id" in DB.

Comments: Hey, Could you post the definition of the Concern and TodoList classes? Here is one guess at what could be the issue (but without the classes it is just a guess)... I'm wondering if you have a collection navigation property on the Concern class that points to TodoList. If you do, then you need to specify this in the WithMany call. But using an empty WithMany call you are telling EF that there isn't an inverse navigation for this relationship. EF would therefore treat the navigation as belonging to a different relationship... and hence introduce a second foreign key into TodoList. ~Rowan
Viewing all 10318 articles
Browse latest View live


Latest Images