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

Reopened Unassigned: EF 6.x EntityObject Generator: SetValidValue misses third parameter [1938]

$
0
0
Hi,

I had to upgrade an EF4 model to EF6. This was quite easy using the EF 6.x EntityObject Generator. The one and only error was in the setter of a complex property:

> _Error 47 The best overloaded method match for 'System.Data.Entity.Core.Objects.DataClasses.StructuralObject.SetValidValue(byte[], bool)' has some invalid arguments

SetValidValue wants the property name as third parameter. This parameter is missing in the code template file. I'm not sure about this but I think the solution is adding a third parameter in the following statement of the "WriteComplexTypeProperty" method:

```
<#=code.FieldName(complexProperty)#> = SetValidValue(<#=code.FieldName(complexProperty)#>, value, "<#=complexProperty.Name#>");
```

At least this works for me.

Regards



Edited Unassigned: EF 6.x EntityObject Generator: SetValidValue misses third parameter [1938]

$
0
0
Hi,

I had to upgrade an EF4 model to EF6. This was quite easy using the EF 6.x EntityObject Generator. The one and only error was in the setter of a complex property:

> _Error 47 The best overloaded method match for 'System.Data.Entity.Core.Objects.DataClasses.StructuralObject.SetValidValue(byte[], bool)' has some invalid arguments

SetValidValue wants the property name as third parameter. This parameter is missing in the code template file. I'm not sure about this but I think the solution is adding a third parameter in the following statement of the "WriteComplexTypeProperty" method:

```
<#=code.FieldName(complexProperty)#> = SetValidValue(<#=code.FieldName(complexProperty)#>, value, "<#=complexProperty.Name#>");
```

At least this works for me.

Regards


Commented Unassigned: EF 6.x EntityObject Generator: SetValidValue misses third parameter [1938]

$
0
0
Hi,

I had to upgrade an EF4 model to EF6. This was quite easy using the EF 6.x EntityObject Generator. The one and only error was in the setter of a complex property:

> _Error 47 The best overloaded method match for 'System.Data.Entity.Core.Objects.DataClasses.StructuralObject.SetValidValue(byte[], bool)' has some invalid arguments

SetValidValue wants the property name as third parameter. This parameter is missing in the code template file. I'm not sure about this but I think the solution is adding a third parameter in the following statement of the "WriteComplexTypeProperty" method:

```
<#=code.FieldName(complexProperty)#> = SetValidValue(<#=code.FieldName(complexProperty)#>, value, "<#=complexProperty.Name#>");
```

At least this works for me.

Regards


Comments: Hi and happy new year. I took two weeks off, not being connected to any net. So I couldn't read your comment until today. I attached a simple project with which I can reproduce the error. The project was created using Visual Studio 2010, using EF 4. The I opened it with Visual Studio 2012, added the EF 6 package, changed the target framework to 4.5.1 and then added the Code Generation Item. The error occurs if I use the EF 6.x EntityObject Generator, it does not occur using the the EF 6.x DbContext Generator.

Created Unassigned: myget nightly builds stalled [1965]

$
0
0
Looks like nothing new since dec 20 last year...

Commented Issue: DropIndex does not remove indexes with non-default name [1923]

$
0
0
In migrations a call to DropIndex that specifies the columns of the index that should be dropped will only work if the name of the index is as per the default naming strategy. If the index was created with the overload of CreateIndex that takes an index name, the corresponding DropIndex will execute without error but without dropping the index.

Example:
```
public override void Up()
{
CreateIndex("dbo.ShippingCostSizeBoundaries", new[] { "ShippingCost_Id", "UpperOrLower" }, true, "IX_ShippingCostSizeBoundaries_Unique_ShippingCost_Id_UpperOrLower");
}

public override void Down()
{
// Executes without error but does not drop the index
DropIndex("dbo.ShippingCostSizeBoundaries", new[] { "ShippingCost_Id", "UpperOrLower" });
}

```

This is EF 6.0.0-RC1.
Comments: Given that the index name has been customized, the appropriate thing to do here is to also modify the DropIndex call in Down to specify the name explicitly. WRT silent failure, I don't remember the specifics of that discussion, but one thing we could do is raise a warning from SQL. Such warnings are output in yellow to the PS console.

Edited Issue: DropIndex does not remove indexes with non-default name [1923]

$
0
0
In migrations a call to DropIndex that specifies the columns of the index that should be dropped will only work if the name of the index is as per the default naming strategy. If the index was created with the overload of CreateIndex that takes an index name, the corresponding DropIndex will execute without error but without dropping the index.

Example:
```
public override void Up()
{
CreateIndex("dbo.ShippingCostSizeBoundaries", new[] { "ShippingCost_Id", "UpperOrLower" }, true, "IX_ShippingCostSizeBoundaries_Unique_ShippingCost_Id_UpperOrLower");
}

public override void Down()
{
// Executes without error but does not drop the index
DropIndex("dbo.ShippingCostSizeBoundaries", new[] { "ShippingCost_Id", "UpperOrLower" });
}

```

This is EF 6.0.0-RC1.

Edited Unassigned: TPH foreign key mapping use same column [1964]

$
0
0
I am using the TPH inheritance mapping on an existing database. That database has a `Tags` table that looks like this:

Table: `Tags`
Column: `Id` (int)
Column: `ItemId` (int)
Column: `TagType` (string)

The `TagType` column is the discriminator column and contains either "usertag" or "movietag". Depending on the type of tag (user- or movietag), the `ItemId` column refers to either the Id of a record in the `Users` or `Movies` table. This results in the following data model, which I have added to a small console application to test it:

namespace ConsoleApplication14
{
using System.Data.Entity;

internal class Program
{
private static void Main()
{
using (var db = new Context())
{
db.Database.Delete();
db.Database.Initialize(false);
}
}
}

public class User
{
public int Id { get; set; }
}

public class Movie
{
public int Id { get; set; }
}

public abstract class Tag
{
public int Id { get; set; }
}

public class UserTag : Tag
{
public int UserId { get; set; }
public virtual User User { get; set; }
}

public class MovieTag : Tag
{
public int MovieId { get; set; }
public virtual Movie Movie { get; set; }
}

public class Context : DbContext
{
public Context()
{
Database.SetInitializer<Context>(null);
}

public DbSet<User> Users { get; set; }
public DbSet<Movie> Movies { get; set; }
public DbSet<UserTag> UserTags { get; set; }
public DbSet<MovieTag> MovieTags { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Tag>()
.Map<UserTag>(m => m.Requires("TagType").HasValue("usertag"))
.Map<MovieTag>(m => m.Requires("TagType").HasValue("movietag"));

modelBuilder.Entity<UserTag>().Property(m => m.UserId).HasColumnName("ItemId");
modelBuilder.Entity<UserTag>().HasRequired(m => m.User).WithMany().HasForeignKey(m => m.UserId);

modelBuilder.Entity<MovieTag>().Property(m => m.MovieId).HasColumnName("ItemId");
modelBuilder.Entity<MovieTag>().HasRequired(m => m.Movie).WithMany().HasForeignKey(m => m.MovieId);
}
}
}

Now when I run this application I get the following exception:

`ItemId: : There is no property with name 'ItemId' defined in the type referred to by Role 'Tag'.`

I don't know how I can prevent this error from happening. It seems to me that this is a situation that occurs more than once in real-life databases, so I hope that there is a way to map this or that this can be fixed.

My application is using Entity Framework 6.0.2.

Closed Unassigned: EF 6.x DbContextGenerator failures: VS2013 referencing incorrect file locations [1960]

$
0
0

#### In Visual Studio 2013 every time/way of adding an EF 6.x DbContextGenerator to a project with or after adding a new Entity Data Model from an existing SQL Server database generates the following errors:

_Compiling transformation: Metadata file 'E:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\..\IDE\EntityFramework.dll' could not be found_

_Compiling transformation: Metadata file 'E:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\..\IDE\Microsoft.Data.Entity.Design.dll' could not be found_

This occurs with Visual Studio 2013 default non-customized installations (have tried Professional and Ultimate versions) on the system C: drive. I have verified that the files _do not_ exist in this incorrect location indicated in the error messages, and that the files _do_ exist in the correct/default location:

```
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\EntityFramework.dll
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Microsoft.Data.Entity.Design.dll
```


I have tried the obvious complete Visual Studio 2013 uninstall/reinstall, same with Entity Framework, trying stock Entity Framework 6.x then each of the stable (and the latest pre-release versions), and this same behavior occurs. Visual Studio keeps looking for the above files in an incorrect location on a different drive from the installation, and the transforming templates fail to generate successfully. The output files simply contain the text "ErrorGeneratingOutput"

I can reproduce this behavior consistently using the simplest of projects, even simply following the steps in the basic EF tutorial at asp.net, [EF Database First with ASP.NET MVC: Creating the Web Application and Data Models ](http://www.asp.net/mvc/tutorials/mvc-5/database-first-development/creating-the-web-application)

Is there a way to repair or uninstall/re-install these EF Tools in Visual Studio 2013 (like VS 2012 where they are seperate download/install) or even manually update the incorrect file reference locations somewhere?
Comments: https://entityframework.codeplex.com/workitem/1782

Closed Unassigned: Several Canonical functions are not handled in the SQL Server Compact provider [1961]

$
0
0

Compare
InitializeCanonicalFunctionHandlers() in src\EntityFramework.SqlServerCompact\SqlGen\SqlGenerator.cs
and
InitializeCanonicalFunctionHandlers() in src\EntityFramework.SqlServer\SqlGen\SqlFunctionCallHandler.cs

Some canonical functions are not handled, including Truncate, Contains, StartsWith, EndsWith, and many date/time functions

Also see the dicscussion here: http://social.msdn.microsoft.com/Forums/sqlserver/en-US/819bb6d2-88b5-4832-9ea0-e8975465848d/sql-server-compact-data-provider-for-ef-does-not-support-some-entity-sql-canonical-functions?forum=sqlce
Comments: https://entityframework.codeplex.com/workitem/1962

Edited Issue: Related to 1709: Migrations with CreateDatabaseIfNotExists Initializer [1958]

$
0
0
Steps and results:
1. Add CreateDatabaseIfNotExists Initializer
1. Enable migrations before creating the DB
1. Create simple model, run so it creates DB
Unhandled Exception: System.Data.Entity.Migrations.Infrastructure.AutomaticMigrationsDisabledException: Unable to update database to match the current model bec ause there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration.
1. Add migration, then run again, works fine
1. Change model, run
Unhandled Exception: System.InvalidOperationException: The model backing the 'BloggingContext' context has changed since the database was created. Consider usin g Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).
1. Add migration for the change, run
Unhandled Exception: System.InvalidOperationException: The model backing the 'BloggingContext' context has changed since the database was created. Consider using Code First Migrations to update the database(http://go.microsoft.com/fwlink/?LinkId=238269).

This exception at step 6 in unexpected. I expected it to work fine.

I manually did update-database to get out of this situation. After I got out of it, I repeated steps 5 and 6 to see the same result.

I also see the exact same behavior with no Initializer.

Commented Issue: Migrations :: changing entity name for which ToTable has been specified fails [1622]

$
0
0
Consider the following context:

``` C#
public class Fish
{
public int Id { get; set; }
}

public class EnglshIsDifficultContext : DbContext
{
public DbSet<Fish> Fishes { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Fish>().ToTable("Fishes");
}
}

```


Enable-Migrations
Add-Migration Mig1
Update-Database

will produce:

``` C#
CreateTable(
"dbo.Fishes",
c => new
{
Id = c.Int(nullable: false, identity: true),
})
.PrimaryKey(t => t.Id);


```

Now, refactor-rename entity name from "Fish" to "Ghoti":

``` C#
public class Ghoti
{
public int Id { get; set; }
}

public class EnglshIsDifficultContext : DbContext
{
public DbSet<Ghoti> Fishes { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Ghoti>().ToTable("Fishes");
}
}
```

Add-Migration Mig2 will produce:

``` C#
CreateTable(
"dbo.Fishes",
c => new
{
Id = c.Int(nullable: false, identity: true),
})
.PrimaryKey(t => t.Id);

DropTable("dbo.Fishes");
```

which will fail with the following exception upon Update-Database:
```
There is already an object named 'Fishes' in the database.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.DispatchTInterceptionContext,TResult(Func`1 operation, TInterceptionContext interceptionContext, Action`1 executing, Action`1 executed)
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext)
at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteNonQuery()
at System.Data.Entity.Migrations.DbMigrator.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement)
at System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable`1 migrationStatements, DbConnection connection)
at System.Data.Entity.Migrations.DbMigrator.<>cDisplayClass32.<ExecuteStatements>b2e()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>cDisplayClass1.<Execute>b0()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.ExecuteTResult(Func`1 operation)
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation)
at System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable`1 migrationStatements)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteStatements(IEnumerable`1 migrationStatements)
at System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, XDocument targetModel, IEnumerable`1 operations, IEnumerable`1 systemOperations, Boolean downgrading, Boolean auto)
at System.Data.Entity.Migrations.DbMigrator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration)
at System.Data.Entity.Migrations.DbMigrator.<>cDisplayClassc.<Update>bb()
at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>cDisplayClass2.<.ctor>b0()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
ClientConnectionId:abda49fe-b9a1-4c61-99c9-1fcc405a8dd4
```
We should try to detect this as noop
Comments: This shows up as a create/drop pair because the table fails the differ heuristic table pairing test. (> 80% member match).

Edited Issue: Designer in VS2013: Generate Database from Model Error: Unable to convert runtime connection string to its design-time equivalent [1838]

$
0
0
This error occurs in the the designer with Visual Studio 2013 when running Generate Database from Model when using a 3rd party provider or even the SQL Server Compact provider in an EDMX based project,.

(The EF6 designer in VS 2012 does works fine when doing this)

The entity connection string in app.config is present and correct.

Also see this on SO : http://stackoverflow.com/questions/19983270/unable-to-convert-runtime-exception-string-to-its-desing-time-equivalent

I have attached a repro project. (Without EF binaries)

The error comes from:
```
TranslateConnectionString(Project project, string invariantName, string connectionString, bool isDesignTime)
```
As per https://entityframework.codeplex.com/discussions/403680 MySQL connector now supports VS2013. We should make sure that either MySQL is not affected by this issue or the fix works for MySQL as well.

There is a related bug which I originally thought was causing the problem but it actually seems to be a separate issue: https://entityframework.codeplex.com/workitem/1869

Edited Feature: Connection resiliency: possible data corruption if connection fails after transaction commit [FixedIn6.1.0-alpha1] [AffectedLastRTM] [1114]

$
0
0
The connection resiliency feature on EF6 automatically deals with database operations that can fail due to transient conditions and need to be retried one or more times until they succeed. The mechanism relies on the ability to observe certain kinds of failures as exceptions on the client side and on the assumption that when one of those failures is observed it will always be caused by an operation that can be retried, either because the operation is idempotent (a rare occurrence in data modification operations in EF) or because its failure guarantees no durable side effects will affect the database (in fact, EF was updated to ensure that by default all database interactions that can modify the data stored on the database are wrapped in a transaction, helping attain the latter).

We have identified a situation in which the current design is insufficient to handle transient failures correctly: due to unstable connectivity it is possible for transaction success notifications to not be properly or timely received on the client side, which can result in an exception being observed on the client that does not correspond to a re-triable operation failing on the server.

Incidentally, if we were to retry on this kind of situation it would most likely cause data corruption, since generally speaking data modification operations produced by EF are not idempotent.

On the other hand even if we didn’t retry we would still have problems: in the case of such failure during SaveChanges no store generated values would be propagated into the in-memory objects leaving the context with change tracking state that is inconsistent with the database. The application would then have to handle the situation by throwing away the context and starting from scratch.

What can we do about the issue?

1. Our highest priority for EF6 should be to avoid causing data corruption. For that we need to make sure that when such situation occurs we do not retry

2. Long term we should look into extending the connection resiliency work to gracefully handle this situation. This could be achieved by:
a. Adding a ‘transaction log’ entity and table to which on each transaction we will insert a new row with a client generated GUID
b. Any time we recognize a failure on a transaction commit we can re-query the database for the GUID value we just generated. If the row is there then we know the transaction didn’t fail and if we are in SaveChanges() we can resume SaveChanges() as normal (including the back propagation of store generated values).

3. Longer term we should keep working with the Managed Providers team to track any work they can do to fix this on their end in a way that doesn't cause as much overhead

4. Possible guidance for EF5 and EF6: part of the solution described in #2 can be implemented as a workaround today. The workaround consists in adding a ‘transaction log’ table and insert a row on each transaction with a client generated GUID. The part that cannot be implemented today is to resume the rest of SaveChanges: while it is possible to ‘accept all changes’ on the context it is not possible to propagate store generated values from the database into the objects in memory if SaveChanges fails (note that if there are not store generated values in the model at all this shouldn’t be a problem).

5. Another alternative form of the workaround is to issue an UPDATE on a table with concurrency control on a timestamp on every transaction. Doing this will cause any subsequent retry to fail with a concurrency violation. Note that this workaround won’t recover store generated values.

The following blog post describes a workaround similar to #4 implemented for applications using ADO.NET with stored procedures:

[SQL Database Connectivity and the Idempotency Issue](http://blogs.msdn.com/b/adonet/archive/2013/03/11/sql-database-connectivity-and-the-idempotency-issue.aspx)

Edited Feature: Provide interception & logging events for transactions [FixedIn6.1.0-alpha1] [AffectedLastRTM] [1256]

$
0
0
This would be in general useful to customize the behavior, to include transaction details in the log and also to enable the implementation of workarounds for the issue described here:

[Connection resiliency: possible data corruption if connection fails after transaction commit](https://entityframework.codeplex.com/workitem/1114).


Edited Issue: [Performance] Produce simpler query expression trees for C# null comparison semantics [FixedIn6.1.0-alpha1] [AffectedLastRTM] [1598]

$
0
0
See https://entityframework.codeplex.com/workitem/1579 for more details. The attached file contains a repro.

In summary the expressions that we generate to compensate for database null comparisons contain terms that are sometimes unnecessary. This leads to different issues:

- Perf regressions because the database is unable to leverage indexes when the predicates are complex
- Large stacks (and potentially stack overflows) because query trees contain additional expressions

We should look at removing the unnecessary terms we add to discriminate between NULL and false when we know that the expression if final (e.g. that it will not be composed over with a negation), e.g., in the following expression:

```
((x = y) AND NOT (x IS NULL OR y IS NULL)) OR (x IS NULL AND y IS NULL)

```

The part 'AND NOT (x IS NULL OR y IS NULL)' is only there to prevent the result of the whole expression from being NULL when x is NULL or y is NULL but both are not simultaneously NULL. When we know that this expression won't be negated then and is only combined with other ORs or ANDs to form the predicate then we can get rid of that term because NULL and false will have the same effects on the results of the query, e.g. rows won't be returned for either NULL or false.

Edited Issue: Error in migration (like issue 1773) missing Discriminator Field [FixedIn6.1.0-alpha1] [AffectedLastRTM] [1775]

$
0
0
With this example

```C#
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ErrorMigration.Model
{
[Table("Contract")]
public class Contract
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; set; }

public DateTime X { get; set; }
}

[Table("InitialContract")]
public class ContractRevision : Contract
{
}

[Table("InitialContract")]
public class InitialContract : Contract
{
}
public class ModelContext : DbContext
{

public DbSet<Contract> Contract { get; set; }

public DbSet<ContractRevision> ContractRevision { get; set; }

public DbSet<InitialContract> InitialContract { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}
}

```


if I execute add-migration I get this result:

```C#
public override void Up()
{
CreateTable(
"dbo.Contract",
c => new
{
Id = c.Long(nullable: false, identity: true),
X = c.DateTime(nullable: false),
})
.PrimaryKey(t => t.Id);

CreateTable(
"dbo.InitialContract",
c => new
{
Id = c.Long(nullable: false),
})
.PrimaryKey(t => t.Id)
.ForeignKey("dbo.Contract", t => t.Id)
.ForeignKey("dbo.Contract", t => t.Id)
.Index(t => t.Id)
.Index(t => t.Id);

}

public override void Down()
{
DropForeignKey("dbo.InitialContract", "Id", "dbo.Contract");
DropForeignKey("dbo.InitialContract", "Id", "dbo.Contract");
DropIndex("dbo.InitialContract", new[] { "Id" });
DropIndex("dbo.InitialContract", new[] { "Id" });
DropTable("dbo.InitialContract");
DropTable("dbo.Contract");
}
```

As you can see, the discriminator is missing.

if I comment the X property in the Contract class, as in the example above

```C#
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ErrorMigration.Model
{
[Table("Contract")]
public class Contract
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; set; }

//public DateTime X { get; set; }
}

[Table("InitialContract")]
public class ContractRevision : Contract
{
}

[Table("InitialContract")]
public class InitialContract : Contract
{
}
public class ModelContext : DbContext
{

public DbSet<Contract> Contract { get; set; }

public DbSet<ContractRevision> ContractRevision { get; set; }

public DbSet<InitialContract> InitialContract { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}
}
```

then I get this migration

``` C#
public override void Up()
{
CreateTable(
"dbo.Contract",
c => new
{
Id = c.Long(nullable: false, identity: true),
})
.PrimaryKey(t => t.Id);

CreateTable(
"dbo.InitialContract",
c => new
{
Id = c.Long(nullable: false),
Discriminator = c.String(nullable: false, maxLength: 128),
})
.PrimaryKey(t => t.Id)
.ForeignKey("dbo.Contract", t => t.Id)
.ForeignKey("dbo.Contract", t => t.Id)
.Index(t => t.Id)
.Index(t => t.Id);

}

public override void Down()
{
DropForeignKey("dbo.InitialContract", "Id", "dbo.Contract");
DropForeignKey("dbo.InitialContract", "Id", "dbo.Contract");
DropIndex("dbo.InitialContract", new[] { "Id" });
DropIndex("dbo.InitialContract", new[] { "Id" });
DropTable("dbo.InitialContract");
DropTable("dbo.Contract");
}
```

Edited Issue: Migrations with Stored Procedures don't update stored procedures when tables change [FixedIn6.1.0-alpha1] [AffectedLastRTM] [1797]

$
0
0
__When looking at this issue please also ensure that data type changes are also scaffolded (originally report in__ https://entityframework.codeplex.com/workitem/1810 __)__

Hello,

With the version EF6.0.0.0, we have found a bug in migration. We use the technology code first with automatic stored procedure .
This following example describe the problem
``` C#
class Company
{
[Required] public int Id {get;set;}

[Required, StringLength(50)] public string Name {get;set;}
}
```
In the first migration, it create table and 3 stored procedure.

After we decide to increase size of Company to 75
``` C#
class Company
{
[Required] public int Id {get;set;}

[Required, StringLength(75)] public string Name {get;set;}
}
```
In the second migration, it update column size but not the size of parameter @Name in stored procedure insert and update

Thanks

Closed Issue: DropIndex does not remove indexes with non-default name [1923]

$
0
0
In migrations a call to DropIndex that specifies the columns of the index that should be dropped will only work if the name of the index is as per the default naming strategy. If the index was created with the overload of CreateIndex that takes an index name, the corresponding DropIndex will execute without error but without dropping the index.

Example:
```
public override void Up()
{
CreateIndex("dbo.ShippingCostSizeBoundaries", new[] { "ShippingCost_Id", "UpperOrLower" }, true, "IX_ShippingCostSizeBoundaries_Unique_ShippingCost_Id_UpperOrLower");
}

public override void Down()
{
// Executes without error but does not drop the index
DropIndex("dbo.ShippingCostSizeBoundaries", new[] { "ShippingCost_Id", "UpperOrLower" });
}

```

This is EF 6.0.0-RC1.
Comments: __EF Team Triage:__ The fact that DropIndex uses the default name is By Design. If you specify a custom name for CreateIndex then you also need to specify the name in DropIndex. We did discuss that it would be easier to understand if you got an error from the DropIndex rather than silently doing nothing. However we intentionally took a change to wrap the generated drop statement in an 'If Index Exists' condition as this is important for a number of other scenarios. Although the change isn't ideal in this particular scenario, we are not planning to change it.

Commented Issue: myget nightly builds stalled [1965]

$
0
0
Looks like nothing new since dec 20 last year...
Comments: The issue is that we are not generating date-stamped packages (which are the ones we upload to MyGet).

Closed Unassigned: EF 6.02 Automatic Migration fails [1963]

$
0
0

__Environment:__

Windows 7 SP1 Home Premium
Visual Studio 2013 Express
MVC 5 (project was created using VS2013 express)
EF 6.02
.Net 4.5 framework
AspNet.Providers.Core 2.0.0
AspNet.Providers 2.0.0
SQL Server 2008 R2
Code-First Models (220 models)

__Web.Config__

```
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
```

```
<connectionStrings>
<add name="ApplicationServices" connectionString="Data Source=localhost; Initial Catalog=aspnetdb; Integrated Security=True;" providerName="System.Data.SqlClient" />
<add name="I2CDB" connectionString="Data Source=localhost; Initial Catalog=I2CDBA; Integrated Security=True;" providerName="System.Data.SqlClient" />
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="Data Source=localhost; Initial Catalog=I2CDB; Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>

```

We have created a fresh new MVC 5 project with EF 6.02 and imported all the Models from our previous MVC4 project (was created using VS 2010 SP1) by doing "Add Existing". I have a large ERP system with 220 entity models. We are using Code-First models.

__Problem__

Our project runs fine in MVC 5 with EF 6.02 and it access the SQL Server 2008 R2 (as well as SQL Server 2012) without a problem as long as the Models Match the database. The Start-up Time is about 60 seconds during a Debugging session, which is reasonable compared with more than 8 minutes with VS 2010 SP1.

However, in case there is a mismatch, then we have a major problem. The start-up time would go up to more than 10 minutes and then an error showing Database not matching the models.

The second major problem, is that we have to use Automatic Migration to update the database, and this when the entire thing fails. If we try to do "update-database -verbose -force" we receive consistently the same exception error shown below, the command just sits there for almost 5 minutes and then it display the following exception.

We tried to use "-script" option but it fails with the same exception. This renders Code-First totally unusable and therefore we can not migrate to the latest VS2013/.Net 4.5 framework/MVC5/EF6

_We have tried to redirect the Connection String to a fresh new database name, and it works fine. So "update-database -verbose -force" will create successfully the complete database. One we try to do any single change, and use Auto Migration, the following exception and behavior persists. We have tried with both SQL Server 2008 R2 and SQL Server 2012_

```
PM> update-database -verbose -force

--- or ---

PM> update-database -verbose -force -script

Using StartUp project 'inv2cash'.
Using NuGet project 'inv2cash'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Target database is: 'I2CDB' (DataSource: localhost, Provider: System.Data.SqlClient, Origin: Configuration).
No pending explicit migrations.

--- it sits here for almost 5 minutes -----

Applying automatic migration: 201401042347019_AutomaticMigration.

--- it sits here for almost another 5 - 7 minutes and then .. boom :-----

System.Runtime.Remoting.RemotingException: Object '/c106cae8_4da0_4b6c_8882_bec38b8d1607/s6aojvpx65n33sjyi_9xvwqb_1369.rem' has been disconnected or does not exist at the server.
at System.Data.Entity.Migrations.Design.ToolingFacade.ToolLogger.Verbose(String sql)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement)
at System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable1 migrationStatements, DbConnection connection)
at System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClass32.<ExecuteStatements>b__2e()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func1 operation)
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation)
at System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable1 migrationStatements)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteStatements(IEnumerable1 migrationStatements)
at System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, XDocument targetModel, IEnumerable1 operations, IEnumerable1 systemOperations, Boolean downgrading, Boolean auto)
at System.Data.Entity.Migrations.DbMigrator.AutoMigrate(String migrationId, XDocument sourceModel, XDocument targetModel, Boolean downgrading)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.AutoMigrate(String migrationId, XDocument sourceModel, XDocument targetModel, Boolean downgrading)
at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable1 pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable1 pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration)
at System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClassc.<Update>b__b()
at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Object '/c106cae8_4da0_4b6c_8882_bec38b8d1607/s6aojvpx65n33sjyi_9xvwqb_1369.rem' has been disconnected or does not exist at the server.
```

This is very disturbing and stopping our migration to VS 2013 and to MVC 5.

Hope it will find some listening ears.

BR

Adel Mansour
Comments: __EF Team Triage:__ Per last comment this is fixed in 6.1.0
Viewing all 9566 articles
Browse latest View live


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