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

Created Unassigned: Inconsistent behaviour with Parent-Children Relations [2809]

$
0
0
The following model has inconsistent behaviour when queried via LINQ with entities:

public class Test
{
public Test()
{
Children = new List<Test>();
}

[Key]
public int Id { get; set; }

public string Name { get; set; }

[ForeignKey(nameof(ParentId))]
public ICollection<Test> Children { get; set; }

public int? ParentId { get; set; }
[ForeignKey(nameof(ParentId))]
public Test Parent { get; set; }

[NotMapped]
public string Path
{
//get { return "Test"; }
get { return Parent != null ? Parent.Path + '.' + Name : Name; }
}
}
Given a simple Context like this:

public class MyContext : DbContext
{
public DbSet<Test> Tests { get; set; }
}
And then adding some data to it (in my case, like this):

Test t = new Test()
{
Text = "Child",
};
Test p = new Test()
{
Text = "Parent",
Children = new List<Test>() { t }
};
t.Parent = p;
ctx.Tests.Add(p);
ctx.SaveChanges();
And then restarting the application (so the Query/Object-Cache is cleared) and then querying like so:

foreach (Test test in ctx.Tests.Where(x => x.Text == "Child"))
{
Console.WriteLine("Is the parent null?: " + (test.Parent == null).ToString());
}
Outputs "true" for the added "Child" object.

However, querying like so:

Console.WriteLine("=== ALL ELEMENTS ===");
foreach (Test test in ctx.Tests)
{
Console.WriteLine("Found t with path " + test.Path);
}
Console.WriteLine("=== FILTERED ELEMENTS ===");
foreach (Test test in ctx.Tests.Where(x => x.Text == "Child" && x.Parent != null))
{
Console.WriteLine("Is the parent null?: " + (test.Parent == null).ToString());
}
Outputs "false" for the added "Child" object.

I tried this on a MySql Database, with both the Devart MySql Provider, and Oracles MySql Provider, and got the same behaviour on both, which leads me to think this is an issue with EntityFramework.
Note that test.ParentId is set to its correct value, just the property test.Parent does not get populated unless you first load the parent objects into the cache (ie, the caching mechanism causes a change in behaviour of population).

I find this behaviour really odd, I'm not sure if this is a bug, but it is very weird that the cache has effects like that.

Best Regards

Edited Unassigned: Inconsistent behaviour with Parent-Children Relations [2809]

$
0
0
The following model has inconsistent behaviour when queried via LINQ with entities:

public class Test
{
public Test()
{
Children = new List<Test>();
}

[Key]
public int Id { get; set; }

public string Name { get; set; }

[ForeignKey(nameof(ParentId))]
public ICollection<Test> Children { get; set; }

public int? ParentId { get; set; }
[ForeignKey(nameof(ParentId))]
public Test Parent { get; set; }

[NotMapped]
public string Path
{
//get { return "Test"; }
get { return Parent != null ? Parent.Path + '.' + Name : Name; }
}
}
Given a simple Context like this:

public class MyContext : DbContext
{
public DbSet<Test> Tests { get; set; }
}
And then adding some data to it (in my case, like this):

Test t = new Test()
{
Text = "Child",
};
Test p = new Test()
{
Text = "Parent",
Children = new List<Test>() { t }
};
t.Parent = p;
ctx.Tests.Add(p);
ctx.SaveChanges();
And then restarting the application (so the Query/Object-Cache is cleared) and then querying like so:

foreach (Test test in ctx.Tests.Where(x => x.Text == "Child" && x.Parent != null))
{
Console.WriteLine("Is the parent null?: " + (test.Parent == null).ToString());
}
Outputs "true" for the added "Child" object.

However, querying like so:

Console.WriteLine("=== ALL ELEMENTS ===");
foreach (Test test in ctx.Tests)
{
Console.WriteLine("Found t with path " + test.Path);
}
Console.WriteLine("=== FILTERED ELEMENTS ===");
foreach (Test test in ctx.Tests.Where(x => x.Text == "Child" && x.Parent != null))
{
Console.WriteLine("Is the parent null?: " + (test.Parent == null).ToString());
}
Outputs "false" for the added "Child" object.

I tried this on a MySql Database, with both the Devart MySql Provider, and Oracles MySql Provider, and got the same behaviour on both, which leads me to think this is an issue with EntityFramework.
Note that test.ParentId is set to its correct value, just the property test.Parent does not get populated unless you first load the parent objects into the cache (ie, the caching mechanism causes a change in behaviour of population).

I find this behaviour really odd, I'm not sure if this is a bug, but it is very weird that the cache has effects like that.

Best Regards

Commented Issue: UpForGrabs: Entity Framework 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/
Comments: I've forked the code and created a fix that we are using internally. You can access is at http://entityframework.codeplex.com/SourceControl/network/forks/bengutt/ToolSet2100ParametersFixItem520 I've followed the first possible solution specified above from divega. This hasn't really solved the bug, it's just moved it to a higher number of tables before you run into the problem again, hoping EF7 will come to my rescue before we get to that number. It does mean however that I've been able to continue working without having to use the very time consuming workaround. Note:- I did have awful problems getting it to build, and I've found the lack of feedback from the command line build process somewhat frustrating. I've had a fair few code analysis errors (CA1704 and CA2204), from code I've not touched. It's probably a lack of experience that's causing my frustration, although having vs2013 and vs2015 installed I think has contributed. To get around the CA1704, CA2204 errors, if you open /src/Strict.ruleset in Visual Studio and unselect:- Microsoft Naming, CA1704 Microsoft Naming, CA2204 I did not commit these changes, you will need to reproduce them (or fix them). This is what I've done to get it to successfully build (both prior and post my changes):- Followed http://entityframework.codeplex.com/wikipage?title=Getting%20and%20Building%20EF%20Tools I found I couldn't open the installer in vs2015 at all, and I had to install version 3.9.1208.0 of the WiX Toolset to get it to build in VS 2013. I then ran BuildEFTools.cmd /t:Install /p:Configuration=Release. It then build fine, but failed to install. I manually ran \bin\_Release\en\EFTools.msi and it did install fine. A second build after cleaning out the output from the first worked fine. Make sure you don't have any instances of visual studio open when running the build. Adding /p:RunCodeAnalysisForEFTools=false will not stop the code analysis as it is forced on a Release build. This has got us up and running again, hope it's of use to others.

Created Unassigned: With Oracle, where clause with more than 1000 values is ignoring the 1001th value [2810]

$
0
0
With Entity Framework 6.1.3 with Oracle.

When having a Where clause with more than 1000 values (ex. 3500 ), Entity Framework is splitting the values because with Oracle, the maximum number of items in a "IN" clause is 1000.

So the generated query is something like :

```
Where Extent1.MyId IN (1,2,3,... 1000) OR IN (1002,1003,.... 2000) ...
```

Every 1000 values, the 1001th is ignored...




Edited Unassigned: With Oracle, Where clause with a Contains having more than 1000 values is ignoring the 1001th value [2810]

$
0
0
With Entity Framework 6.1.3 with Oracle.

When having a Where clause with more than 1000 values (ex. 3500 ), Entity Framework is splitting the values because with Oracle, the maximum number of items in a "IN" clause is 1000.

So the generated query is something like :

```
Where Extent1.MyId IN (1,2,3,... 1000) OR IN (1002,1003,.... 2000) ...
```

Every 1000 values, the 1001th is ignored...




Commented Unassigned: 6.1.3 Inheritance Bug (6.1.1 works fine) [2798]

$
0
0
With this model

public class Class1
{
[Key]
public int Id { get; set; }

public virtual string MyProperty { get; set; }
// other properties
}

public class Class3 : Class1
{
[Required]
public override string MyProperty { get; set; }

public string Class3Prop { get; set; }
}


public class TestContext : DbContext
{
public TestContext(DbConnection connection) : base(connection, true) { }

public DbSet<Class1> C1s { get; set; }
public DbSet<Class3> C3s { get; set; }


}

I expect that Class3.MyProperty is required and Class1.MyProperty is not required.

With EF 6.1.1 everything's working fine (in SQL Server the MyProperty field is nullable).
With EF 6.1.3 both Class3.MyProperty and Class1.MyProperty are interpreted as Required (and in SQL Server MyProperty field is not nullable)

Comments: @bubibubi - you are right, the API is actually `IsOptional()` in EF6. We will re-discuss in triage based on the info you provided about validating the derived type and not the base type.

Closed Unassigned: Introduce SparseAttribute attribute [2805]

$
0
0
I would like to suggest introduction of a SparseAttribute, like if I have this code:

```
public class HenrikDahlsClassForShowingRowanMiller
{
public Guid ID { get; set; }

[Timestamp]
public byte[] Version { get; set; }

[Sparse]
public Guid? NonPKGuid { get; set; }
}

```
This SQL should be generated:
```
CREATE TABLE [NonSpecifiedSchema].[HenrikDahlsClassForShowingRowanMillers] (
[ID] [uniqueidentifier] ROWGUIDCOL NOT NULL DEFAULT newsequentialid(),
[Version] rowversion NOT NULL,
[NonPKGuid] [uniqueidentifier] SPARSE,
CONSTRAINT [PK_NonSpecifiedSchema.HenrikDahlsClassForShowingRowanMillers] PRIMARY KEY ([ID])
)
```
[Documentation](https://msdn.microsoft.com/en-us/library/cc280604(v=sql.120).aspx)


Best regards,

Henrik Dahl

Comments: __EF Triage:__ This isn't a very common scenario, so it's not something we would add native support to in EF. The ability to extend migrations would nicely handle this though - here is a blog post that covers how you would do that http://romiller.com/2012/01/16/customizing-code-first-migrations-provider/.

Edited Issue: 6.1.3 Inheritance Bug (6.1.1 works fine) [2798]

$
0
0
With this model

public class Class1
{
[Key]
public int Id { get; set; }

public virtual string MyProperty { get; set; }
// other properties
}

public class Class3 : Class1
{
[Required]
public override string MyProperty { get; set; }

public string Class3Prop { get; set; }
}


public class TestContext : DbContext
{
public TestContext(DbConnection connection) : base(connection, true) { }

public DbSet<Class1> C1s { get; set; }
public DbSet<Class3> C3s { get; set; }


}

I expect that Class3.MyProperty is required and Class1.MyProperty is not required.

With EF 6.1.1 everything's working fine (in SQL Server the MyProperty field is nullable).
With EF 6.1.3 both Class3.MyProperty and Class1.MyProperty are interpreted as Required (and in SQL Server MyProperty field is not nullable)


Commented Issue: 6.1.3 Inheritance Bug (6.1.1 works fine) [2798]

$
0
0
With this model

public class Class1
{
[Key]
public int Id { get; set; }

public virtual string MyProperty { get; set; }
// other properties
}

public class Class3 : Class1
{
[Required]
public override string MyProperty { get; set; }

public string Class3Prop { get; set; }
}


public class TestContext : DbContext
{
public TestContext(DbConnection connection) : base(connection, true) { }

public DbSet<Class1> C1s { get; set; }
public DbSet<Class3> C3s { get; set; }


}

I expect that Class3.MyProperty is required and Class1.MyProperty is not required.

With EF 6.1.1 everything's working fine (in SQL Server the MyProperty field is nullable).
With EF 6.1.3 both Class3.MyProperty and Class1.MyProperty are interpreted as Required (and in SQL Server MyProperty field is not nullable)

Comments: @Andriy - can you dig into this a little, we remember making changes around this in EF6.1.3 but we're not sure what our intention was.

Edited Unassigned: With Oracle, Where clause with a Contains having more than 1000 values is ignoring the 1001th value [2810]

$
0
0

EDIT: The problem is due to the Oracle provider, not Entity Framework...

With Entity Framework 6.1.3 with Oracle.

When having a Where clause with more than 1000 values (ex. 3500 ), Entity Framework is splitting the values because with Oracle, the maximum number of items in a "IN" clause is 1000.

So the generated query is something like :

```
Where Extent1.MyId IN (1,2,3,... 1000) OR IN (1002,1003,.... 2000) ...
```

Every 1000 values, the 1001th is ignored...




Commented Issue: UpForGrabs: Inconsistent behavior for related entities in AddOrUpdate depending on whether root entity is new or existing [2128]

$
0
0
Working with a common many-to-many scenario, code first, EF 6.02.

```
Product >-< Category
```

I have a context with `MigrateDatabaseToLatestVersion` initializer. In the configurations's `Seed` method I add a few products and categories and establish the many to many by adding products to `Category.Products`.

The essential code (where `db` is a `DbContext`):

```
db.Products.AddOrUpdate(x => x.Name, p1, p2, p3, p4, p5, p6); // p1 etc. are products
var shoes = db.Categories.Create();
// set properties

shoes.Products.Add(p1);
shoes.Products.Add(p4);
shoes.Products.Add(p6);

// More categories

db.Categories.AddOrUpdate(x => x.CategoryName, sports, accessories, shoes);
```

When the database is created everything is fine.

__With an existing database__ I try to add a new product in an existing category. This code runs after the code above, before the `SaveChanges` call.

```
var p7 = db.Products.Create();
db.Products.AddOrUpdate(x => x.Name, p7);
shoes.Products.Add(p7)
```

The result is that the new product is saved, but not the many to many association. This is because at this point, `shoes` is in a `Detached` state, so the change tracker doesn't notice the addition.

Now if instead of `shoes.Products.Add` I do

```
p7.Categories.Add(shoes);
```

the association is saved, but _all existing products in `shoes` are duplicated_. I understand that this is because `shoes`, and all its products, are marked as `Added`.

If I do

```
db.Entry(shoes).State = EntityState.Unchanged;
```

I get a duplicate key exception, which I don't understand, because `shoes` is `Detached`.

The only way I'm aware of to get this working is

```
shoes = db.Categories.Single(c => c.CategoryName == shoes.CategoryName);
shoes.Products.Add(p7);
```

So, finally, my question. You guys probably have good reasons not to attach existing entities in an `AddOrUpdate` call. However, the above scenario would become much more transparent and intuitive if it _did_ attach existing entities.

It's probably a big issue to change this behavior, but could it be an optional feature of `AddOrUpdate`, as a third parameter `attachExisting`?
Comments: New reports of this issue at: - https://github.com/aspnet/EntityFramework/issues/2960 - http://stackoverflow.com/questions/20300035/ The behavior is unexpected and affects very simple scenarios. Clearing up release field to bring it back to triage so that we can consider our options.

Edited Issue: UpForGrabs: Inconsistent behavior for related entities in AddOrUpdate depending on whether root entity is new or existing [2128]

$
0
0
Working with a common many-to-many scenario, code first, EF 6.02.

```
Product >-< Category
```

I have a context with `MigrateDatabaseToLatestVersion` initializer. In the configurations's `Seed` method I add a few products and categories and establish the many to many by adding products to `Category.Products`.

The essential code (where `db` is a `DbContext`):

```
db.Products.AddOrUpdate(x => x.Name, p1, p2, p3, p4, p5, p6); // p1 etc. are products
var shoes = db.Categories.Create();
// set properties

shoes.Products.Add(p1);
shoes.Products.Add(p4);
shoes.Products.Add(p6);

// More categories

db.Categories.AddOrUpdate(x => x.CategoryName, sports, accessories, shoes);
```

When the database is created everything is fine.

__With an existing database__ I try to add a new product in an existing category. This code runs after the code above, before the `SaveChanges` call.

```
var p7 = db.Products.Create();
db.Products.AddOrUpdate(x => x.Name, p7);
shoes.Products.Add(p7)
```

The result is that the new product is saved, but not the many to many association. This is because at this point, `shoes` is in a `Detached` state, so the change tracker doesn't notice the addition.

Now if instead of `shoes.Products.Add` I do

```
p7.Categories.Add(shoes);
```

the association is saved, but _all existing products in `shoes` are duplicated_. I understand that this is because `shoes`, and all its products, are marked as `Added`.

If I do

```
db.Entry(shoes).State = EntityState.Unchanged;
```

I get a duplicate key exception, which I don't understand, because `shoes` is `Detached`.

The only way I'm aware of to get this working is

```
shoes = db.Categories.Single(c => c.CategoryName == shoes.CategoryName);
shoes.Products.Add(p7);
```

So, finally, my question. You guys probably have good reasons not to attach existing entities in an `AddOrUpdate` call. However, the above scenario would become much more transparent and intuitive if it _did_ attach existing entities.

It's probably a big issue to change this behavior, but could it be an optional feature of `AddOrUpdate`, as a third parameter `attachExisting`?

Commented Issue: UpForGrabs: Inconsistent behavior for related entities in AddOrUpdate depending on whether root entity is new or existing [2128]

$
0
0
Working with a common many-to-many scenario, code first, EF 6.02.

```
Product >-< Category
```

I have a context with `MigrateDatabaseToLatestVersion` initializer. In the configurations's `Seed` method I add a few products and categories and establish the many to many by adding products to `Category.Products`.

The essential code (where `db` is a `DbContext`):

```
db.Products.AddOrUpdate(x => x.Name, p1, p2, p3, p4, p5, p6); // p1 etc. are products
var shoes = db.Categories.Create();
// set properties

shoes.Products.Add(p1);
shoes.Products.Add(p4);
shoes.Products.Add(p6);

// More categories

db.Categories.AddOrUpdate(x => x.CategoryName, sports, accessories, shoes);
```

When the database is created everything is fine.

__With an existing database__ I try to add a new product in an existing category. This code runs after the code above, before the `SaveChanges` call.

```
var p7 = db.Products.Create();
db.Products.AddOrUpdate(x => x.Name, p7);
shoes.Products.Add(p7)
```

The result is that the new product is saved, but not the many to many association. This is because at this point, `shoes` is in a `Detached` state, so the change tracker doesn't notice the addition.

Now if instead of `shoes.Products.Add` I do

```
p7.Categories.Add(shoes);
```

the association is saved, but _all existing products in `shoes` are duplicated_. I understand that this is because `shoes`, and all its products, are marked as `Added`.

If I do

```
db.Entry(shoes).State = EntityState.Unchanged;
```

I get a duplicate key exception, which I don't understand, because `shoes` is `Detached`.

The only way I'm aware of to get this working is

```
shoes = db.Categories.Single(c => c.CategoryName == shoes.CategoryName);
shoes.Products.Add(p7);
```

So, finally, my question. You guys probably have good reasons not to attach existing entities in an `AddOrUpdate` call. However, the above scenario would become much more transparent and intuitive if it _did_ attach existing entities.

It's probably a big issue to change this behavior, but could it be an optional feature of `AddOrUpdate`, as a third parameter `attachExisting`?
Comments: Probably the easiest way to offer a solution (of sorts) is returning the tracked objects from `AddOrUpdate`, i.e. either the entities fetched by `set.SingleOrDefault` or the original entities, now in an `Added` state. This could be documented in the public method's XML doc. The inner method would look like private static IEnumerable<TEntity> AddOrUpdate<TEntity>( this DbSet<TEntity> set, IEnumerable<PropertyPath> identifyingProperties, InternalSet<TEntity> internalSet, params TEntity[] entities) where TEntity : class { DebugCheck.NotNull(set); DebugCheck.NotNull(identifyingProperties); DebugCheck.NotNull(entities); var keyProperties = GetKeyProperties(typeof(TEntity), internalSet); var parameter = Expression.Parameter(typeof(TEntity)); foreach (var entity in entities) { var matchExpression = identifyingProperties.Select( pi => Expression.Equal( Expression.Property(parameter, pi.Single()), Expression.Constant(pi.Last().GetValue(entity, null)))) .Aggregate<BinaryExpression, Expression>( null, (current, predicate) => (current == null) ? predicate : Expression.AndAlso(current, predicate)); var existing = set.SingleOrDefault(Expression.Lambda<Func<TEntity, bool>>(matchExpression, new[] { parameter })); if (existing != null) { foreach (var keyProperty in keyProperties) { keyProperty.Single().GetPropertyInfoForSet().SetValue(entity, keyProperty.Single().GetValue(existing, null), null); } internalSet.InternalContext.Owner.Entry(existing).CurrentValues.SetValues(entity); yield return existing; } else { internalSet.Add(entity); yield return entity; } } }

Commented Unassigned: EF 6.1.3 is VERY slow [2801]

$
0
0
EF 6.1.3 has some __serious__ performance issues. Even a simple query is many times slower than for example in EF 4.1. Only setting context.Configuration.AutoDetectChangesEnabled = false is helping in some cases but this shouldn't be the permanent solution.
Comments: __EF Team Triage:__ This is a very general report and there isn't really anything actionable here. If you have specific code examples where you are seeing a performance regression then we would be happy to act on them.

Commented Unassigned: Allow generating migration code for a custom MigrationOperation from CSharpMigrationCodeGenerator [2799]

$
0
0
Currently, the CSharpMigrationCodeGenerator must have a specific Generate method for each specific MigrationOperation in the migration. If there is a custom MigrationOperation in the list of migrations, it falls back to the Generate method for the AddColumnOperation, which fails with the following exception:

_The best overloaded method match for 'System.Data.Entity.Migrations.Design.CSharpMigrationCodeGenerator.Generate(System.Data.Entity.Migrations.Model.AddColumnOperation, System.Data.Entity.Migrations.Utilities.IndentedTextWriter)' has some invalid arguments_

The CSharpMigrationCodeGenerator should work more like the SqlServerMigrationSqlGenerator, where there is a virtual Generate method for MigrationOperation:
```
protected virtual void Generate(MigrationOperation migrationOperation)

```
As:
```
protected virtual void Generate(MigrationOperation migrationOperation, IndentedTextWriter writer)

```
In this way, developers could override this virtual method when creating a class that derives from CSharpMigrationCodeGenerator the same way it is currently possible with the SqlServerMigrationSqlGenerator class.

Without this, the workaround is to either reimplement the CSharpMigrationCodeGenerator or skip the code migration step for custom migration operations and translate each into a SqlOperation.

As a side note, since there is already a GetDefaultNamespaces virtual method, we can register any custom namespaces required to support the custom MigrationOperation types, so there is no issue with the migration class being generated with broken references.

-- Travis Schettler
Comments: Ah, yes I misunderstood what you were asking for - that make sense. Will just having the ability to generate code for a custom `MigrationOperation` be enough to enable your scenario, or would it also require changes to make the `ModelDiffer` more open too (currently it is very closed)? How do you go about getting an instance of your custom operation into the list that is passed to the C# generator? ~Rowan

Edited Issue: Block installing EF6.x in UWP apps [2803]

$
0
0
I wanted to use EntityFramework on my Windows Universal app (Win10). So, I went to "Nuget package manager" and installed "Entity Framework 6.1.3" package. Installation was successfull, no errors occured. Then I've tried to create MyDbContext:DbContext class. I found that System.Data.Entities namespace is missing and I am not able to use Entity Framework at all.
In System.Data only System.Data.Common is present.
Same issue was present in Win8.1/Windows Phone 8.1 app.

Does Entity Framework supports Windows 10 apps and how to reach its classes?

Commented Issue: Block installing EF6.x in UWP apps [2803]

$
0
0
I wanted to use EntityFramework on my Windows Universal app (Win10). So, I went to "Nuget package manager" and installed "Entity Framework 6.1.3" package. Installation was successfull, no errors occured. Then I've tried to create MyDbContext:DbContext class. I found that System.Data.Entities namespace is missing and I am not able to use Entity Framework at all.
In System.Data only System.Data.Common is present.
Same issue was present in Win8.1/Windows Phone 8.1 app.

Does Entity Framework supports Windows 10 apps and how to reach its classes?
Comments: EF6.x does not work in Universal Apps. We are enabling this in EF7. We should be more explicit about blocking the install on these platforms - changing the title and assigning to EF6.2 to make this change.

Commented Unassigned: Attribute uniqueidentifier PK with ROWGUIDCOL [2796]

$
0
0
Hello!

If the PK is of type ROWGUIDCOL it should be attributed with ROWGUIDCOL in the synthesized SQL code.


Best regards,

Henrik Dahl

Comments: Hi Henrik, It seems like the scenarios where specifying `ROWGUIDCOL` provides benefit are pretty minimal (File Stream and Merge Replication). I'm not sure how much they would overlap with scenarios where EF is creating the database with migrations in a real world application. To me it seems like this would be a scenario where overriding the `SqlServerMigrationSqlGenerator` to add `ROWGUIDCOL` to GUID keys would be fine for the limited set of folks who may need this. Henrik, did you have a scenario where you wanted this in a real world application? ~Rowan

Commented Unassigned: Enable Migrations in MVC throws File not Found Error [2806]

$
0
0
I'm new to using MVC, and when working through the tutorials regarding migrations in Visual Studio 2013 I appear to have broken the tie-in to EntityFramework in the Package Manager console.

I believe this started when I updated the EntityFramework to version 6.1.3, But that appears to be incompatible with the MVC Controller scaffolding. So I rolled it back to version 5.0.0.

When I now enter the command ```enable-migrations```

I get the following error:

```
Exception calling "CreateInstanceFrom" with "8" argument(s): "Could not load file or assembly 'EntityFramework, Version=5.0.0.0 , Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified."
At D:\ss\CAP\CAP_MVC_Dev_2\CAP_MVC\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:431 char:31
+ $domain.CreateInstanceFrom <<<< (
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodTargetInvocation
```

The file ```EntityFramework.psm1``` exists where it is described above, but the error appears to be in that file? How is ```$domain.CreateInstanceFrom``` missing, and where from? Uninstalling and reinstalling the EntityFramework package makes no difference.

I've tried creating new projects from scratch and this error persists across them. An uninstall/reinstall of Visual Studio 2013 has not resolved the issue either, nor has destroying the connected database and starting again with an empty one.
Comments: __EF Team Triage:__ Would you be able to share a project that reproduces this issue? We don't see anything obviously wrong here, so there must be a specific scenario in your setup that is stopping things from working.

Edited Issue: Migrationing from EF5 to 6.1.2 fails for SqlCE (follow-up on #2659) [2807]

$
0
0
Reporting this to note that [work item #2659](https://entityframework.codeplex.com/workitem/2659) has __not__ been resolved for all use cases.

We ship a desktop application using EF and SQL CE and perform migrations programmatically as needed - we can't easily perform a disjointed upgrade (going from 5 to 6 to 6.1.2, migrating at each step) as the work item resolution suggests. It would be much more more helpful if the migration table code was updated to cover all historical scenarios.

It looks like I'll have to stick with EF 5.0.0 until there are newer versions that can actually cleanly support upgrading.
Viewing all 9566 articles
Browse latest View live


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