Quantcast
Channel: entityframework Issue Tracker Rss Feed
Viewing all 9566 articles
Browse latest View live

Commented Issue: DbConfiguration.SetInitializer Reference Context Problem [671]

$
0
0
I'm unable to use the SetInitializer method of EF6 DbConfiguration. Here's the problem I'm encountering.

I have one project for my model, HotelRoomsModel, which inherits DbContext.
I'm using Migrations so in the same project, I have a Configuration file.

In a second project I created a DbConfiguration class and one of the configuraitons is to set the database initializer for my model.

namespace DataLayer.DbConfigurations
{
public class CustomDbConfiguration : DbConfiguration
{
public CustomDbConfiguration()
{
SetDefaultConnectionFactory(new LocalDbConnectionFactory("v11.0"));
SetDatabaseInitializer(new MigrateDatabaseToLatestVersion
<HotelRoomsModel, HotelModel.HotelMigrations.Configuration>());
}
}
}

In order to specify the context, this project needs a reference to the model's project.

Now I need to "trigger" the configuration. One method as per your overview is to use an attribute in the DbContext. However, that would require the model project to have a reference to the DbConfiguration project which would create a circular reference.

So that's problem #1 because my understanding of the specs and the overview samples was that I should be able to do this.

The alternate suggestion is to specify the DbConfiguration in the app.config file.

<entityFramework codeConfigurationType="DataLayer.DbConfigurations.CustomDbConfiguration,DbConfigurations"/>

I have yet another project which is a console app. In the main method all I'm doing is initializing my model.

If I run without debugging, I get a stackoverflow exception.

If I debug I can see it hit the code as follows:

1) Instantiate HotelsRoomsModel class
2) Instantiate CustomDbConfiguration class
3) SetDefaultCOnnetionFactory in CustomDbConfiguraiton
4) SetDatabaseInitalizer in CustomerDbConfiguration
5) Then it seems to recursively instantiate this class over and over until it overflows.

I stopped it before it overflowed even then the inellitrace file I collected is over 16MB and too big to attach.

Can you easily reproduce it? Would you like me to attach a solution? Or am I doing something very obviously wrong that you can see in the description above?


Comments: Commit: f344923ea335

Edited Issue: DbConfiguration.SetInitializer Reference Context Problem [671]

$
0
0
I'm unable to use the SetInitializer method of EF6 DbConfiguration. Here's the problem I'm encountering.

I have one project for my model, HotelRoomsModel, which inherits DbContext.
I'm using Migrations so in the same project, I have a Configuration file.

In a second project I created a DbConfiguration class and one of the configuraitons is to set the database initializer for my model.

namespace DataLayer.DbConfigurations
{
public class CustomDbConfiguration : DbConfiguration
{
public CustomDbConfiguration()
{
SetDefaultConnectionFactory(new LocalDbConnectionFactory("v11.0"));
SetDatabaseInitializer(new MigrateDatabaseToLatestVersion
<HotelRoomsModel, HotelModel.HotelMigrations.Configuration>());
}
}
}

In order to specify the context, this project needs a reference to the model's project.

Now I need to "trigger" the configuration. One method as per your overview is to use an attribute in the DbContext. However, that would require the model project to have a reference to the DbConfiguration project which would create a circular reference.

So that's problem #1 because my understanding of the specs and the overview samples was that I should be able to do this.

The alternate suggestion is to specify the DbConfiguration in the app.config file.

<entityFramework codeConfigurationType="DataLayer.DbConfigurations.CustomDbConfiguration,DbConfigurations"/>

I have yet another project which is a console app. In the main method all I'm doing is initializing my model.

If I run without debugging, I get a stackoverflow exception.

If I debug I can see it hit the code as follows:

1) Instantiate HotelsRoomsModel class
2) Instantiate CustomDbConfiguration class
3) SetDefaultCOnnetionFactory in CustomDbConfiguraiton
4) SetDatabaseInitalizer in CustomerDbConfiguration
5) Then it seems to recursively instantiate this class over and over until it overflows.

I stopped it before it overflowed even then the inellitrace file I collected is over 16MB and too big to attach.

Can you easily reproduce it? Would you like me to attach a solution? Or am I doing something very obviously wrong that you can see in the description above?


Created Issue: NuGet Package install fails with F# projects [891]

$
0
0
Reported via blog - http://blogs.msdn.com/b/adonet/archive/2012/12/10/ef6-alpha-2-available-on-nuget.aspx?CommentPosted=true#10394085

I got the following exception, doesn't look like a major issue but want to update. I am writing my code in F# if that has anything to do with it.

PM> Install-Package EntityFramework -Pre

You are downloading EntityFramework from Microsoft, the license agreement to which is available at go.microsoft.com/fwlink. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device.

Successfully installed 'EntityFramework 6.0.0-alpha2'.

Successfully added 'EntityFramework 6.0.0-alpha2' to DALEntities.

Exception calling "CreateInstanceFrom" with "8" argument(s): "Type 'Microsoft.VisualStudio.FSharp.ProjectSystem.Automation.OAProject' in assembly

'FSharp.ProjectSystem.Base, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable."

At C:\Users\shashi\SkyDrive\Code\CommonDAL\packages\EntityFramework.6.0.0-alpha2\tools\install.ps1:10 char:5

+ $appDomain.CreateInstanceFrom(

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException

+ FullyQualifiedErrorId : SerializationException

Type 'get-help EntityFramework' to see all available Entity Framework commands.

PM>

Commented Issue: Support BeginTransaction on DbContext.Database.Connection [645]

$
0
0
This issue has been reported in UserVoice (currently with 6 votes):

http://data.uservoice.com/forums/72025-entity-framework-feature-suggestions/suggestions/1917783-support-transactions-for-dbcontext-database-sqlque

On one hand we expose the store connection on DbContext.Database.Connection by design. On the other hand, we currently rely on the EntityConnection.CurrentTransaction internal property to wire up transactions to the database commands created for ObjectContext.ExecuteStoreQuery and ObjectContext.ExecuteStoreCommand, which is not set correctly by just beginning a local transaction on the underlying connection.

We potentially have worse problems on save, since we use the same EntityConnection.CurrentTransaction property to wire up the transaction used in individual commands in the update pipeline and in the logic that figures out whether we need to create our own local transaction in SaveChanges.
Comments: Changes adding a UseTransaction() on Database that allows the user to use an external store transaction, plus BeginTransaction() + overload that allow user to begin a DbTransactionContext that can be used in the normal using() {...} pattern - were checked in with commit #3e8c6ae.

Created Issue: Inconsistent state when model has 1-many FK navigation on entity with composite key. [892]

$
0
0
When model has 1-many FK navigation and composite key we get into invalid state and fail on insert with non-obvious exception:

Violation of PRIMARY KEY constraint 'PK_dbo.ArubaTasks'. Cannot insert duplicate key in object 'dbo.ArubaTasks'.

Consider the following model:

public class ArubaRun
{
public int Id { get; set; }
public string Name { get; set; }
public int Purpose { get; set; }
public ICollection<ArubaTask> Tasks { get; set; }
}

public class ArubaTask
{
public int Id { get; set; }
public string Name { get; set; }
public bool Deleted { get; set; }
}

public class ArubaContext : DbContext
{
static ArubaContext()
{
Database.SetInitializer(new ArubaInitializer());
}

public DbSet<ArubaRun> Runs { get; set; }
public DbSet<ArubaTask> Tasks { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// composite key, non-integer key
modelBuilder.Entity<ArubaTask>().HasKey(k => new { k.Id, k.Name });

// need to map key explicitly, otherwise we get into invalid state
//modelBuilder.Entity<ArubaRun>().HasMany(r => r.Tasks).WithRequired().Map(m => { });
}
}

public class ArubaInitializer : DropCreateDatabaseIfModelChanges<ArubaContext>
{
private const int EntitiesCount = 10;

protected override void Seed(ArubaContext context)
{
var runs = InitializeRuns();
var tasks = InitializeTasks();


for (var i = 0; i < EntitiesCount; i++)
{
for (var j = 0; j < 3; j++)
{
runs[i].Tasks.Add(tasks[(i + j) % EntitiesCount]);
}
}

for (int i = 0; i < EntitiesCount; i++)
{
context.Runs.Add(runs[i]);
context.Tasks.Add(tasks[i]);
}

context.SaveChanges();

base.Seed(context);
}

private ArubaRun[] InitializeRuns()
{
var runs = new ArubaRun[EntitiesCount];
for (var i = 0; i < EntitiesCount; i++)
{
var run = new ArubaRun
{
Id = i,
Name = "Run Name" + i,
Purpose = i + 10,
Tasks = new List<ArubaTask>(),
};
runs[i] = run;
}

return runs;
}

private ArubaTask[] InitializeTasks()
{
var tasks = new ArubaTask[EntitiesCount];
for (int i = 0; i < EntitiesCount; i++)
{
var task = new ArubaTask
{
Id = i / 2,
Name = i % 2 == 0 ? "Foo" : "Bar",
Deleted = i % 3 == 0,
};
tasks[i] = task;
}

return tasks;
}
}


When we create database for it, we (incorrectly) pick Id par of Task key as a FK (see attached picture for details). We should have created a new FK column instead.


Stack trace:
System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(System.Collections.Generic.Dictionary<int,object> identifierValues, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.Data.Entity.Core.Mapping.Update.Internal.PropagatorResult,object>> generatedValues, System.Data.Entity.Internal.IDbCommandInterceptor commandInterceptor)

System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()

System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update.AnonymousMethod__2(System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator ut)

System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update<int>(System.Data.Entity.Core.IEntityStateManager entityCache, int noChangesResult, System.Func<System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator,int> updateFunction, bool throwOnClosedConnection)

System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update(System.Data.Entity.Core.IEntityStateManager entityCache, bool throwOnClosedConnection)

System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore.AnonymousMethod__20()

System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction<int>(System.Func<int> func, bool throwOnExistingTransaction, bool startLocalTransaction)

System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(System.Data.Entity.Core.Objects.SaveOptions options, bool throwOnExistingTransaction)

System.Data.Entity.Core.Objects.ObjectContext.SaveChanges.AnonymousMethod__12()

System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.ProtectedExecute<int>(System.Func<int> func)

System.Data.Entity.Infrastructure.ExecutionStrategy.Execute<int>(System.Func<int> func)

System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(System.Data.Entity.Core.Objects.SaveOptions options)

System.Data.Entity.Internal.InternalContext.SaveChanges()

System.Data.Entity.Internal.LazyInternalContext.SaveChanges()

System.Data.Entity.DbContext.SaveChanges()

Edited Issue: Inconsistent state when model has 1-many FK navigation on entity with composite key. [892]

$
0
0
When model has 1-many FK navigation and composite key we get into invalid state and fail on insert with non-obvious exception:

Violation of PRIMARY KEY constraint 'PK_dbo.ArubaTasks'. Cannot insert duplicate key in object 'dbo.ArubaTasks'.

Consider the following model:

public class ArubaRun
{
public int Id { get; set; }
public string Name { get; set; }
public int Purpose { get; set; }
public ICollection<ArubaTask> Tasks { get; set; }
}

public class ArubaTask
{
public int Id { get; set; }
public string Name { get; set; }
public bool Deleted { get; set; }
}

public class ArubaContext : DbContext
{
static ArubaContext()
{
Database.SetInitializer(new ArubaInitializer());
}

public DbSet<ArubaRun> Runs { get; set; }
public DbSet<ArubaTask> Tasks { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// composite key, non-integer key
modelBuilder.Entity<ArubaTask>().HasKey(k => new { k.Id, k.Name });

// need to map key explicitly, otherwise we get into invalid state
//modelBuilder.Entity<ArubaRun>().HasMany(r => r.Tasks).WithRequired().Map(m => { });
}
}

public class ArubaInitializer : DropCreateDatabaseIfModelChanges<ArubaContext>
{
private const int EntitiesCount = 10;

protected override void Seed(ArubaContext context)
{
var runs = InitializeRuns();
var tasks = InitializeTasks();


for (var i = 0; i < EntitiesCount; i++)
{
for (var j = 0; j < 3; j++)
{
runs[i].Tasks.Add(tasks[(i + j) % EntitiesCount]);
}
}

for (int i = 0; i < EntitiesCount; i++)
{
context.Runs.Add(runs[i]);
context.Tasks.Add(tasks[i]);
}

context.SaveChanges();

base.Seed(context);
}

private ArubaRun[] InitializeRuns()
{
var runs = new ArubaRun[EntitiesCount];
for (var i = 0; i < EntitiesCount; i++)
{
var run = new ArubaRun
{
Id = i,
Name = "Run Name" + i,
Purpose = i + 10,
Tasks = new List<ArubaTask>(),
};
runs[i] = run;
}

return runs;
}

private ArubaTask[] InitializeTasks()
{
var tasks = new ArubaTask[EntitiesCount];
for (int i = 0; i < EntitiesCount; i++)
{
var task = new ArubaTask
{
Id = i / 2,
Name = i % 2 == 0 ? "Foo" : "Bar",
Deleted = i % 3 == 0,
};
tasks[i] = task;
}

return tasks;
}
}


When we create database for it, we (incorrectly) pick Id par of Task key as a FK (see attached picture for details). We should have created a new FK column instead.


Stack trace:
System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(System.Collections.Generic.Dictionary<int,object> identifierValues, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.Data.Entity.Core.Mapping.Update.Internal.PropagatorResult,object>> generatedValues, System.Data.Entity.Internal.IDbCommandInterceptor commandInterceptor)

System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()

System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update.AnonymousMethod__2(System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator ut)

System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update<int>(System.Data.Entity.Core.IEntityStateManager entityCache, int noChangesResult, System.Func<System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator,int> updateFunction, bool throwOnClosedConnection)

System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update(System.Data.Entity.Core.IEntityStateManager entityCache, bool throwOnClosedConnection)

System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore.AnonymousMethod__20()

System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction<int>(System.Func<int> func, bool throwOnExistingTransaction, bool startLocalTransaction)

System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(System.Data.Entity.Core.Objects.SaveOptions options, bool throwOnExistingTransaction)

System.Data.Entity.Core.Objects.ObjectContext.SaveChanges.AnonymousMethod__12()

System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.ProtectedExecute<int>(System.Func<int> func)

System.Data.Entity.Infrastructure.ExecutionStrategy.Execute<int>(System.Func<int> func)

System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(System.Data.Entity.Core.Objects.SaveOptions options)

System.Data.Entity.Internal.InternalContext.SaveChanges()

System.Data.Entity.Internal.LazyInternalContext.SaveChanges()

System.Data.Entity.DbContext.SaveChanges()

Commented Issue: Inconsistent state when model has 1-many FK navigation on entity with composite key. [892]

$
0
0
When model has 1-many FK navigation and composite key we get into invalid state and fail on insert with non-obvious exception:

Violation of PRIMARY KEY constraint 'PK_dbo.ArubaTasks'. Cannot insert duplicate key in object 'dbo.ArubaTasks'.

Consider the following model:

public class ArubaRun
{
public int Id { get; set; }
public string Name { get; set; }
public int Purpose { get; set; }
public ICollection<ArubaTask> Tasks { get; set; }
}

public class ArubaTask
{
public int Id { get; set; }
public string Name { get; set; }
public bool Deleted { get; set; }
}

public class ArubaContext : DbContext
{
static ArubaContext()
{
Database.SetInitializer(new ArubaInitializer());
}

public DbSet<ArubaRun> Runs { get; set; }
public DbSet<ArubaTask> Tasks { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// composite key, non-integer key
modelBuilder.Entity<ArubaTask>().HasKey(k => new { k.Id, k.Name });

// need to map key explicitly, otherwise we get into invalid state
//modelBuilder.Entity<ArubaRun>().HasMany(r => r.Tasks).WithRequired().Map(m => { });
}
}

public class ArubaInitializer : DropCreateDatabaseIfModelChanges<ArubaContext>
{
private const int EntitiesCount = 10;

protected override void Seed(ArubaContext context)
{
var runs = InitializeRuns();
var tasks = InitializeTasks();


for (var i = 0; i < EntitiesCount; i++)
{
for (var j = 0; j < 3; j++)
{
runs[i].Tasks.Add(tasks[(i + j) % EntitiesCount]);
}
}

for (int i = 0; i < EntitiesCount; i++)
{
context.Runs.Add(runs[i]);
context.Tasks.Add(tasks[i]);
}

context.SaveChanges();

base.Seed(context);
}

private ArubaRun[] InitializeRuns()
{
var runs = new ArubaRun[EntitiesCount];
for (var i = 0; i < EntitiesCount; i++)
{
var run = new ArubaRun
{
Id = i,
Name = "Run Name" + i,
Purpose = i + 10,
Tasks = new List<ArubaTask>(),
};
runs[i] = run;
}

return runs;
}

private ArubaTask[] InitializeTasks()
{
var tasks = new ArubaTask[EntitiesCount];
for (int i = 0; i < EntitiesCount; i++)
{
var task = new ArubaTask
{
Id = i / 2,
Name = i % 2 == 0 ? "Foo" : "Bar",
Deleted = i % 3 == 0,
};
tasks[i] = task;
}

return tasks;
}
}


When we create database for it, we (incorrectly) pick Id par of Task key as a FK (see attached picture for details). We should have created a new FK column instead.


Stack trace:
System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(System.Collections.Generic.Dictionary<int,object> identifierValues, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.Data.Entity.Core.Mapping.Update.Internal.PropagatorResult,object>> generatedValues, System.Data.Entity.Internal.IDbCommandInterceptor commandInterceptor)

System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()

System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update.AnonymousMethod__2(System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator ut)

System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update<int>(System.Data.Entity.Core.IEntityStateManager entityCache, int noChangesResult, System.Func<System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator,int> updateFunction, bool throwOnClosedConnection)

System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update(System.Data.Entity.Core.IEntityStateManager entityCache, bool throwOnClosedConnection)

System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore.AnonymousMethod__20()

System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction<int>(System.Func<int> func, bool throwOnExistingTransaction, bool startLocalTransaction)

System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(System.Data.Entity.Core.Objects.SaveOptions options, bool throwOnExistingTransaction)

System.Data.Entity.Core.Objects.ObjectContext.SaveChanges.AnonymousMethod__12()

System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.ProtectedExecute<int>(System.Func<int> func)

System.Data.Entity.Infrastructure.ExecutionStrategy.Execute<int>(System.Func<int> func)

System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(System.Data.Entity.Core.Objects.SaveOptions options)

System.Data.Entity.Internal.InternalContext.SaveChanges()

System.Data.Entity.Internal.LazyInternalContext.SaveChanges()

System.Data.Entity.DbContext.SaveChanges()

Comments: to make the code work, one needs to add the following line to the OnModelCreating: modelBuilder.Entity<ArubaRun>().HasMany(r => r.Tasks).WithRequired().Map(m => { });

Commented Issue: Inconsistent state when model has 1-many FK navigation on entity with composite key. [892]

$
0
0
When model has 1-many FK navigation and composite key we get into invalid state and fail on insert with non-obvious exception:

Violation of PRIMARY KEY constraint 'PK_dbo.ArubaTasks'. Cannot insert duplicate key in object 'dbo.ArubaTasks'.

Consider the following model:

public class ArubaRun
{
public int Id { get; set; }
public string Name { get; set; }
public int Purpose { get; set; }
public ICollection<ArubaTask> Tasks { get; set; }
}

public class ArubaTask
{
public int Id { get; set; }
public string Name { get; set; }
public bool Deleted { get; set; }
}

public class ArubaContext : DbContext
{
static ArubaContext()
{
Database.SetInitializer(new ArubaInitializer());
}

public DbSet<ArubaRun> Runs { get; set; }
public DbSet<ArubaTask> Tasks { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// composite key, non-integer key
modelBuilder.Entity<ArubaTask>().HasKey(k => new { k.Id, k.Name });

// need to map key explicitly, otherwise we get into invalid state
//modelBuilder.Entity<ArubaRun>().HasMany(r => r.Tasks).WithRequired().Map(m => { });
}
}

public class ArubaInitializer : DropCreateDatabaseIfModelChanges<ArubaContext>
{
private const int EntitiesCount = 10;

protected override void Seed(ArubaContext context)
{
var runs = InitializeRuns();
var tasks = InitializeTasks();


for (var i = 0; i < EntitiesCount; i++)
{
for (var j = 0; j < 3; j++)
{
runs[i].Tasks.Add(tasks[(i + j) % EntitiesCount]);
}
}

for (int i = 0; i < EntitiesCount; i++)
{
context.Runs.Add(runs[i]);
context.Tasks.Add(tasks[i]);
}

context.SaveChanges();

base.Seed(context);
}

private ArubaRun[] InitializeRuns()
{
var runs = new ArubaRun[EntitiesCount];
for (var i = 0; i < EntitiesCount; i++)
{
var run = new ArubaRun
{
Id = i,
Name = "Run Name" + i,
Purpose = i + 10,
Tasks = new List<ArubaTask>(),
};
runs[i] = run;
}

return runs;
}

private ArubaTask[] InitializeTasks()
{
var tasks = new ArubaTask[EntitiesCount];
for (int i = 0; i < EntitiesCount; i++)
{
var task = new ArubaTask
{
Id = i / 2,
Name = i % 2 == 0 ? "Foo" : "Bar",
Deleted = i % 3 == 0,
};
tasks[i] = task;
}

return tasks;
}
}


When we create database for it, we (incorrectly) pick Id par of Task key as a FK (see attached picture for details). We should have created a new FK column instead.


Stack trace:
System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(System.Collections.Generic.Dictionary<int,object> identifierValues, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.Data.Entity.Core.Mapping.Update.Internal.PropagatorResult,object>> generatedValues, System.Data.Entity.Internal.IDbCommandInterceptor commandInterceptor)

System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()

System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update.AnonymousMethod__2(System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator ut)

System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update<int>(System.Data.Entity.Core.IEntityStateManager entityCache, int noChangesResult, System.Func<System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator,int> updateFunction, bool throwOnClosedConnection)

System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update(System.Data.Entity.Core.IEntityStateManager entityCache, bool throwOnClosedConnection)

System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore.AnonymousMethod__20()

System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction<int>(System.Func<int> func, bool throwOnExistingTransaction, bool startLocalTransaction)

System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(System.Data.Entity.Core.Objects.SaveOptions options, bool throwOnExistingTransaction)

System.Data.Entity.Core.Objects.ObjectContext.SaveChanges.AnonymousMethod__12()

System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.ProtectedExecute<int>(System.Func<int> func)

System.Data.Entity.Infrastructure.ExecutionStrategy.Execute<int>(System.Func<int> func)

System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(System.Data.Entity.Core.Objects.SaveOptions options)

System.Data.Entity.Internal.InternalContext.SaveChanges()

System.Data.Entity.Internal.LazyInternalContext.SaveChanges()

System.Data.Entity.DbContext.SaveChanges()

Comments: this also repros in EF5, so its NOT a regression

Created Issue: Migrate from console does not follow timeout param in connection string [893]

$
0
0
When executing a migration from the console on a database with a table containing 30-50 columns and 1million rows the migration fails with a timeout exception regardless of the timeout parameter in the connection string and the timeout set on the server. It appears to time out after approx 1 minute.

It would be very useful to have an explicit timeout switch or at the very least for it to use the one in the connection string.

Note: when running the migration from within Visual Studio this does not occur.

Closed Issue: Split edmx file into one file per entity [877]

$
0
0
We recently created a Database Project that used the SQL Server Data Tools to create schema files from our database. The ease and effectiveness of having a separate file for each database object made me wonder why it is so much more complicated to manage our EF database-first model.

Right now, EDMX files sort of pull double duty. They define the model, and they also define layout and relationships in the Visual Studio Entity Designer. I think it would make a lot more sense to split EDMX files into a **single file per entity**, and then update the Entity Designer to still be able to display "the whole picture", including relationships, despite the definitions being in separate files. Obviously, doing this would necessitate keeping Designer-specific data separate from model definitions, which is really what is needed anyway.

This sort of change would make EF a whole lot safer and easier to use for teams. I know that right now some people suggest making separate EDMX files for different "parts" of the database, but this doesn't really work for us as most of our tables are interconnected in some way and it doesn't make a lot of sense to arbitrarily slice those relationships at certain points just to keep the size of our EDMX file down.
Comments: **EF Team Triage:** Thank you for suggesting this change. This isn't something that we feel would be a good solution for the EF Designer. I realize it's not exactly what you are suggesting, but the concept of Diagrams (introduced in EF5) does break up the concept of the all up model and individual views of the model. If you want each entity to be modeled in a separate file then we would recommend using Code First instead of the EF Designer.

Edited Issue: Power Tools: Reverse engineer does not honor registered T4 processors [622]

$
0
0
The VS and command line hosts for the T4 processor allow registering custom directives that can be processed by types registered under HKLM\Software\Microsoft\VisualStudio\$(shellversion)\TextTemplating\DirectiveProcessors (found under HKLM\Software\Wow6432Node in 64 bit machines).

Apparently the way we run T4 templates in the EF PowerTools, e.g. for reverse engineering of a database into Code First classes does not honor registered processors. This could affect any directive either we add in our .ttinclude files or any directive that customers using custom templates want to add.

Edited Issue: EF.dll tries to load SQL Server provider even when not using SQL Server [587]

$
0
0
EntityFramework.SqlServer is loaded when SaveChanges is called even when the SQL Server provider is not being used. Usually this is not noticed because the assembly is available and so the load succeeds. If the assembly is not available then the following exception is generated.

Unhandled Exception: System.TypeInitializationException: The type initializer for 'ExtentPlaceholderCreator' threw an ex
ception. ---> System.TypeLoadException: Method 'GetDbProviderManifestToken' in type 'System.Data.Entity.SqlServer.SqlPro
viderServices' from assembly 'EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e0
89' does not have an implementation.
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOn
ly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOn
ly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, Stac
kCrawlMark& stackMark)
at System.Type.GetType(String typeName, Boolean throwOnError)
at System.Data.Entity.Config.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantNam
e)
at System.Data.Entity.Config.ProviderServicesFactory.GetInstanceByConvention(String providerInvariantName)
at System.Data.Entity.Config.DefaultProviderServicesResolver.GetService(Type type, Object key)
at System.Data.Entity.Config.CachingDependencyResolver.<>c__DisplayClass1.<GetService>b__0(Tuple`2 k)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at System.Data.Entity.Config.CachingDependencyResolver.GetService(Type type, Object key)
at System.Data.Entity.Config.ResolverChain.<>c__DisplayClass3.<GetService>b__0(IDbDependencyResolver r)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at System.Data.Entity.Config.ResolverChain.GetService(Type type, Object key)
at System.Data.Entity.Config.RootDependencyResolver.GetService(Type type, Object key)
at System.Data.Entity.Config.ResolverChain.<>c__DisplayClass3.<GetService>b__0(IDbDependencyResolver r)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at System.Data.Entity.Config.ResolverChain.GetService(Type type, Object key)
at System.Data.Entity.Config.CompositeResolver`2.GetService(Type type, Object key)
at System.Data.Entity.Config.IDbDependencyResolverExtensions.GetService[T](IDbDependencyResolver resolver, Object key
)
at System.Data.Entity.Spatial.SpatialServicesLoader.LoadDefaultServices()
at System.Data.Entity.Spatial.DbSpatialServices.<.cctor>b__0()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Lazy`1.get_Value()
at System.Data.Entity.Spatial.DbSpatialServices.get_Default()
at System.Data.Entity.Spatial.DbGeometry.FromText(String wellKnownText)
at System.Data.Entity.Core.Mapping.Update.Internal.Propagator.ExtentPlaceholderCreator.InitializeTypeDefaultMap()
at System.Data.Entity.Core.Mapping.Update.Internal.Propagator.ExtentPlaceholderCreator..cctor()
--- End of inner exception stack trace ---
at System.Data.Entity.Core.Mapping.Update.Internal.Propagator.ExtentPlaceholderCreator.CreatePlaceholder(EntitySetBas
e extent)
at System.Data.Entity.Core.Mapping.Update.Internal.Propagator.Visit(DbScanExpression node)
at System.Data.Entity.Core.Common.CommandTrees.DbScanExpression.Accept[TResultType](DbExpressionVisitor`1 visitor)
at System.Data.Entity.Core.Mapping.Update.Internal.UpdateExpressionVisitor`1.Visit(DbExpression expression)
at System.Data.Entity.Core.Mapping.Update.Internal.Propagator.Visit(DbProjectExpression node)
at System.Data.Entity.Core.Common.CommandTrees.DbProjectExpression.Accept[TResultType](DbExpressionVisitor`1 visitor)

at System.Data.Entity.Core.Mapping.Update.Internal.Propagator.Propagate(UpdateTranslator parent, EntitySet table, DbQ
ueryCommandTree umView)
at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.<ProduceDynamicCommands>d__b.MoveNext()
at System.Linq.Enumerable.<ConcatIterator>d__71`1.MoveNext()
at System.Data.Entity.Core.Mapping.Update.Internal.UpdateCommandOrderer..ctor(IEnumerable`1 commands, UpdateTranslato
r translator)
at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.ProduceCommands()
at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<Update>b__2(UpdateTranslator ut)
at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update[T](IEntityStateManager entityCache, T noChanges
Result, Func`2 updateFunction, Boolean throwOnClosedConnection)
at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update(IEntityStateManager entityCache, Boolean throwO
nClosedConnection)
at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options)
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 ConsoleApplication1.Program.Main(String[] args) in c:\Users\avickers\Documents\Visual Studio 2012\Projects\Console
Application1\ConsoleApplication1\Program.cs:line 49

Edited Issue: Entity Framework VS 2012 designer fails calling sp_executesql with too many parameters when updating large model from database [520]

$
0
0
We recently upgraded to VS 2012 (still targeting .net 4.0) so we could use the new model diagrams to support having a larger merged data model. We were able to merge our models by hand into one combined model and can use it without issue at runtime (402 tables with lots of associations).

However when I try to update the model from the database, the designer gets an error:

Error 3 An error occurred while executing the command definition. See the inner exception for details.
The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Too many parameters were provided in this RPC request. The maximum is 2100.

SQL Server (2008 r2) has a fixed limit of 2100 parameters that can be passed to a stored procedure. EF is using a call to sp_executesql where it is passing 2400 parameters. While debugging the exeception in visual studio, we saw may duplicates like using one parameter for each table for the catalog, the schema and the table name rather than reusing the catalog and schema parms (that alone would've kept the call under the limit). Here's an example (notice each SchemaName has a different parm for a value that can't be different since you don't support mutliple databases in the same edmx!):

WHERE (([Extent1].[CatalogName] LIKE @p0) AND ([Extent1].[SchemaName] LIKE @p1) AND ([Extent1].[Name] LIKE @p2)) OR

(([Extent1].[CatalogName] LIKE @p3) AND ([Extent1].[SchemaName] LIKE @p4) AND ([Extent1].[Name] LIKE @p5)) OR (([Extent1].

[CatalogName] LIKE @p6) AND ([Extent1].[SchemaName] LIKE @p7) AND ([Extent1].[Name] LIKE @p8)) OR (([Extent1].[CatalogName]

LIKE @p9) AND ([Extent1].[SchemaName] LIKE @p10) AND ([Extent1].[Name] LIKE @p11)) OR (([Extent1].[CatalogName] LIKE @p12)

AND ([Extent1].[SchemaName] LIKE @p13) AND ([Extent1].[Name] LIKE @p14)) OR (([Extent1].[CatalogName] LIKE @p15) AND

([Extent1].[SchemaName] LIKE @p16) AND ([Extent1].[Name] LIKE @p17)) OR (([Extent1].[CatalogName] LIKE @p18) AND ([Extent1].

[SchemaName] LIKE @p19) AND ([Extent1].[Name] LIKE @p20)) OR (([Extent1].[CatalogName] LIKE @p21) AND ([Extent1].

[SchemaName] LIKE @p22) AND ([Extent1].[Name] LIKE @p23)) OR (([Extent1].[CatalogName] LIKE @p24) AND ([Extent1].

[SchemaName] LIKE @p25) AND ([Extent1].[Name] LIKE @p26)) OR (([Extent1].[CatalogName] LIKE @p27) AND ([Extent1].

[SchemaName] LIKE @p28) AND ([Extent1].[Name] LIKE @p29)) OR (([Extent1].[CatalogName] LIKE @p30) AND ([Extent1].

[SchemaName] LIKE @p31) AND ([Extent1].[Name] LIKE @p32)) OR (([Extent1].[CatalogName] LIKE @p33) AND ([Extent1].

[SchemaName] LIKE @p34) AND ([Extent1].[Name] LIKE @p35)) OR (([Extent1].[CatalogName] LIKE @p36) AND ([Extent1].

[SchemaName] LIKE @p37) AND ([Extent1].[Name] LIKE @p38)) OR (([Extent1].[CatalogName] LIKE @p39) AND ([Extent1].

[SchemaName] LIKE @p40) AND ([Extent1].[Name] LIKE @p41)) OR (([Extent1].[CatalogName] LIKE @p42) AND ([Extent1].

[SchemaName] LIKE @p43) AND ([Extent1].[Name] LIKE @p44)) OR (([Extent1].[CatalogName] LIKE @p45) AND ([Extent1].

[SchemaName] LIKE @p46) AND ([Extent1].[Name] LIKE @p47)) OR (([Extent1].[CatalogName] LIKE @p48) AND ([Extent1].


See more on this post: http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/aafb63c4-61df-4d8d-9373-df78d6f7d686/

Edited Issue: Power Tools: Reverse engineer does not honor registered T4 processors [622]

$
0
0
The VS and command line hosts for the T4 processor allow registering custom directives that can be processed by types registered under HKLM\Software\Microsoft\VisualStudio\$(shellversion)\TextTemplating\DirectiveProcessors (found under HKLM\Software\Wow6432Node in 64 bit machines).

Apparently the way we run T4 templates in the EF PowerTools, e.g. for reverse engineering of a database into Code First classes does not honor registered processors. This could affect any directive either we add in our .ttinclude files or any directive that customers using custom templates want to add.

Edited Issue: Code First pipeline performance issues [848]

$
0
0
A large (but trivial) Code First model with around 1900 entities a customer shared with us shows a perf regression of around 70% on DbModelBuilder.Build(). Moreover they are complaining they cannot use Code First even with EF5 because it takes much time at application startup compared with EDMX. Here is a breakdown obtained in my machine, in milliseconds:

EF5 RTM
DbModelBuilder creation 2,324
DbModelBuilder.Build() 80,233
DbModel.Compile() 8,686
DbCompiledModel.CreateObjectContext() 808
First query (includes view generation) 16,616
Total 108,666

EF6 alpha 2
DbModelBuilder creation 2,739
DbModelBuilder.Build() 138,723
DbModel.Compile() 13,032
DbCompiledModel.CreateObjectContext() 1,280
First query (includes view generation) 20,643
Total 176,417

They also claim that total start up time for the same model based on EDMX is around 20 seconds, and that when using KeyAttribute to configure entity keys the Code First pipeline can process the model much faster than when the entity keys are specified using the HasKey fluent API.

Edited Issue: Breaking change in DbExpressionVisitor classes [764]

$
0
0
It appears that we made a breaking change when adding DbInExpression support. Specifically, new abstract members were added to the generic and non-generic DbExpressionVisitor classes:

/// <summary>
/// Typed visitor pattern method for DbInExpression.
/// </summary>
/// <param name="expression"> The DbInExpression that is being visited. </param>
/// <returns> An instance of TResultType. </returns>
public abstract TResultType Visit(DbInExpression expression);


/// <summary>
/// Visitor pattern method for DbInExpression.
/// </summary>
/// <param name="expression"> The DbInExpression that is being visited. </param>
public abstract void Visit(DbInExpression expression);

We should either decide to explicitly make a breaking change and force new providers to support the new expression or make these methods virtual, throw, and ensure that they are not called if the provider has not opted in to the new feature.

Edited Issue: Regression caused by Enums: EF4.3.1 on .NET 4 / VS2012 - The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type [596]

$
0
0
We're using EF 4.3.1 code-first under .NET 4.0 and VS2012. We have a query that looks similar to the following:

ctx.Set<Entities.A>().Select(a => new DTO.A { Id = a.Id, Name = a.Name }).ToArray();

Entities.A is defined in an assembly called Entities and DTO.A is defined in an assembly called DTO. Under VS2010 EF 4.3 this worked fine, but under EF 5.0 it throws the following exception:

Schema specified is not valid. Errors:
The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'A'. Previously found CLR type 'Entities.A', newly found CLR type 'DTO.A'.

Stack trace is

at System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(ObjectItemCollection objectItemCollection, Assembly assembly, Boolean loadReferencedAssemblies, EdmItemCollection edmItemCollection, Action'1 logLoadMessage)
at System.Data.Metadata.Edm.ObjectItemCollection.ImplicitLoadAssemblyForType(Type type, EdmItemCollection edmItemCollection)
at System.Data.Metadata.Edm.MetadataWorkspace.ImplicitLoadAssemblyForType(Type type, Assembly callingAssembly)
at System.Data.Objects.ELinq.ExpressionConverter.TryGetValueLayerType(Type linqType, TypeUsage& type)
at System.Data.Objects.ELinq.ExpressionConverter.GetCastTargetType(TypeUsage fromType, Type toClrType, Type fromClrType, Boolean preserveCastForDateTime)
at System.Data.Objects.ELinq.ExpressionConverter.CreateCastExpression(DbExpression source, Type toClrType, Type fromClrType)
at System.Data.Objects.ELinq.ExpressionConverter.ConvertTranslator.TranslateUnary(ExpressionConverter parent, UnaryExpression unary, DbExpression operand)
at System.Data.Objects.ELinq.ExpressionConverter.UnaryTranslator.TypedTranslate(ExpressionConverter parent, UnaryExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.UnaryTranslator.TypedTranslate(ExpressionConverter parent, UnaryExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.MemberInitTranslator.TypedTranslate(ExpressionConverter parent, MemberInitExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input, DbExpressionBinding& binding)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SelectTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.MemberInitTranslator.TypedTranslate(ExpressionConverter parent, MemberInitExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input, DbExpressionBinding& binding)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SelectTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateSet(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.UnarySequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.Convert()
at System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)

I'd understand the problem if the types were in the same assembly (a long documented issue with EF whereby it cannot disambiguate using just the entity name), but from a different assembly?

Is this a regression, it used to work...?

Edited Issue: Enums in a different assembly triggers "The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type" with EF4 app on .NET 4.5 [596]

$
0
0
We're using EF 4.3.1 code-first under .NET 4.0 and VS2012. We have a query that looks similar to the following:

ctx.Set<Entities.A>().Select(a => new DTO.A { Id = a.Id, Name = a.Name }).ToArray();

Entities.A is defined in an assembly called Entities and DTO.A is defined in an assembly called DTO. Under VS2010 EF 4.3 this worked fine, but under EF 5.0 it throws the following exception:

Schema specified is not valid. Errors:
The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'A'. Previously found CLR type 'Entities.A', newly found CLR type 'DTO.A'.

Stack trace is

at System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(ObjectItemCollection objectItemCollection, Assembly assembly, Boolean loadReferencedAssemblies, EdmItemCollection edmItemCollection, Action'1 logLoadMessage)
at System.Data.Metadata.Edm.ObjectItemCollection.ImplicitLoadAssemblyForType(Type type, EdmItemCollection edmItemCollection)
at System.Data.Metadata.Edm.MetadataWorkspace.ImplicitLoadAssemblyForType(Type type, Assembly callingAssembly)
at System.Data.Objects.ELinq.ExpressionConverter.TryGetValueLayerType(Type linqType, TypeUsage& type)
at System.Data.Objects.ELinq.ExpressionConverter.GetCastTargetType(TypeUsage fromType, Type toClrType, Type fromClrType, Boolean preserveCastForDateTime)
at System.Data.Objects.ELinq.ExpressionConverter.CreateCastExpression(DbExpression source, Type toClrType, Type fromClrType)
at System.Data.Objects.ELinq.ExpressionConverter.ConvertTranslator.TranslateUnary(ExpressionConverter parent, UnaryExpression unary, DbExpression operand)
at System.Data.Objects.ELinq.ExpressionConverter.UnaryTranslator.TypedTranslate(ExpressionConverter parent, UnaryExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.UnaryTranslator.TypedTranslate(ExpressionConverter parent, UnaryExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.MemberInitTranslator.TypedTranslate(ExpressionConverter parent, MemberInitExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input, DbExpressionBinding& binding)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SelectTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.MemberInitTranslator.TypedTranslate(ExpressionConverter parent, MemberInitExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input, DbExpressionBinding& binding)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SelectTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateSet(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.UnarySequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.Convert()
at System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)

I'd understand the problem if the types were in the same assembly (a long documented issue with EF whereby it cannot disambiguate using just the entity name), but from a different assembly?

Is this a regression, it used to work...?

Edited Issue: An enums in a different assembly triggers "The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type" for EF4 app on .NET 4.5 [596]

$
0
0
We're using EF 4.3.1 code-first under .NET 4.0 and VS2012. We have a query that looks similar to the following:

ctx.Set<Entities.A>().Select(a => new DTO.A { Id = a.Id, Name = a.Name }).ToArray();

Entities.A is defined in an assembly called Entities and DTO.A is defined in an assembly called DTO. Under VS2010 EF 4.3 this worked fine, but under EF 5.0 it throws the following exception:

Schema specified is not valid. Errors:
The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'A'. Previously found CLR type 'Entities.A', newly found CLR type 'DTO.A'.

Stack trace is

at System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(ObjectItemCollection objectItemCollection, Assembly assembly, Boolean loadReferencedAssemblies, EdmItemCollection edmItemCollection, Action'1 logLoadMessage)
at System.Data.Metadata.Edm.ObjectItemCollection.ImplicitLoadAssemblyForType(Type type, EdmItemCollection edmItemCollection)
at System.Data.Metadata.Edm.MetadataWorkspace.ImplicitLoadAssemblyForType(Type type, Assembly callingAssembly)
at System.Data.Objects.ELinq.ExpressionConverter.TryGetValueLayerType(Type linqType, TypeUsage& type)
at System.Data.Objects.ELinq.ExpressionConverter.GetCastTargetType(TypeUsage fromType, Type toClrType, Type fromClrType, Boolean preserveCastForDateTime)
at System.Data.Objects.ELinq.ExpressionConverter.CreateCastExpression(DbExpression source, Type toClrType, Type fromClrType)
at System.Data.Objects.ELinq.ExpressionConverter.ConvertTranslator.TranslateUnary(ExpressionConverter parent, UnaryExpression unary, DbExpression operand)
at System.Data.Objects.ELinq.ExpressionConverter.UnaryTranslator.TypedTranslate(ExpressionConverter parent, UnaryExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.UnaryTranslator.TypedTranslate(ExpressionConverter parent, UnaryExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.MemberInitTranslator.TypedTranslate(ExpressionConverter parent, MemberInitExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input, DbExpressionBinding& binding)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SelectTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.MemberInitTranslator.TypedTranslate(ExpressionConverter parent, MemberInitExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input, DbExpressionBinding& binding)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SelectTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateSet(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.UnarySequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.Convert()
at System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)

I'd understand the problem if the types were in the same assembly (a long documented issue with EF whereby it cannot disambiguate using just the entity name), but from a different assembly?

Is this a regression, it used to work...?

Edited Issue: An enums in a different assembly triggers "The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type" for EF4.x app on .NET 4.5 [596]

$
0
0
We're using EF 4.3.1 code-first under .NET 4.0 and VS2012. We have a query that looks similar to the following:

ctx.Set<Entities.A>().Select(a => new DTO.A { Id = a.Id, Name = a.Name }).ToArray();

Entities.A is defined in an assembly called Entities and DTO.A is defined in an assembly called DTO. Under VS2010 EF 4.3 this worked fine, but under EF 5.0 it throws the following exception:

Schema specified is not valid. Errors:
The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'A'. Previously found CLR type 'Entities.A', newly found CLR type 'DTO.A'.

Stack trace is

at System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(ObjectItemCollection objectItemCollection, Assembly assembly, Boolean loadReferencedAssemblies, EdmItemCollection edmItemCollection, Action'1 logLoadMessage)
at System.Data.Metadata.Edm.ObjectItemCollection.ImplicitLoadAssemblyForType(Type type, EdmItemCollection edmItemCollection)
at System.Data.Metadata.Edm.MetadataWorkspace.ImplicitLoadAssemblyForType(Type type, Assembly callingAssembly)
at System.Data.Objects.ELinq.ExpressionConverter.TryGetValueLayerType(Type linqType, TypeUsage& type)
at System.Data.Objects.ELinq.ExpressionConverter.GetCastTargetType(TypeUsage fromType, Type toClrType, Type fromClrType, Boolean preserveCastForDateTime)
at System.Data.Objects.ELinq.ExpressionConverter.CreateCastExpression(DbExpression source, Type toClrType, Type fromClrType)
at System.Data.Objects.ELinq.ExpressionConverter.ConvertTranslator.TranslateUnary(ExpressionConverter parent, UnaryExpression unary, DbExpression operand)
at System.Data.Objects.ELinq.ExpressionConverter.UnaryTranslator.TypedTranslate(ExpressionConverter parent, UnaryExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.UnaryTranslator.TypedTranslate(ExpressionConverter parent, UnaryExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.MemberInitTranslator.TypedTranslate(ExpressionConverter parent, MemberInitExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input, DbExpressionBinding& binding)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SelectTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.MemberInitTranslator.TypedTranslate(ExpressionConverter parent, MemberInitExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input, DbExpressionBinding& binding)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SelectTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateSet(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.UnarySequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.Convert()
at System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)

I'd understand the problem if the types were in the same assembly (a long documented issue with EF whereby it cannot disambiguate using just the entity name), but from a different assembly?

Is this a regression, it used to work...?
Viewing all 9566 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>