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

Commented Issue: One-One relationship with non-generated keys throws unless key values are set on both principal and dependent entities [886]

$
0
0
In 1-1 relationship, if entity keys are not database generated, user has to provide key values for both principal and dependent, otherwise we get (not very helpful) exception:
Multiplicity constraint violated. The role 'ArubaRun_RunOwner_Source' of the relationship 'OneToOneNonGeneratedKeyIssue.ArubaRun_RunOwner' has multiplicity 1 or 0..1.

I would expect this to work, update pipeline should populate the dependent key values based on the values of principal. (just like it's done for database generated keys)

Issue repros for the following model:


public class ArubaOwner
{
public int Id { get; set; }
public ArubaRun OwnedRun { get; set; }
}

public class ArubaRun
{
public int Id { get; set; }
public ArubaOwner RunOwner { get; set; }
}

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

public DbSet<ArubaOwner> Owners { get; set; }
public DbSet<ArubaRun> Runs { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// non-generated key
modelBuilder.Entity<ArubaOwner>().Property(p => p.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
modelBuilder.Entity<ArubaRun>().Property(p => p.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

modelBuilder.Entity<ArubaRun>().HasRequired(r => r.RunOwner).WithRequiredDependent(o => o.OwnedRun);
}
}

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

protected override void Seed(ArubaContext context)
{
var owners = InitializeOwners();
var runs = InitializeRuns();

for (var i = 0; i < EntitiesCount; i++)
{
owners[i].OwnedRun = runs[i];
}

for (var i = 0; i < EntitiesCount; i++)
{
runs[i].RunOwner = owners[i];
}

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

context.SaveChanges();

base.Seed(context);
}


private ArubaOwner[] InitializeOwners()
{
var owners = new ArubaOwner[EntitiesCount];
for (var i = 0; i < EntitiesCount; i++)
{
var owner = new ArubaOwner
{
Id = i,
};
owners[i] = owner;
}

return owners;
}

private ArubaRun[] InitializeRuns()
{
var runs = new ArubaRun[EntitiesCount];
for (var i = 0; i < EntitiesCount; i++)
{
var run = new ArubaRun
{
};
runs[i] = run;
}

return runs;
}
}


Stack trace:

System.Data.Entity.Core.Objects.EntityEntry.WillNotRefSteal(System.Data.Entity.Core.Objects.DataClasses.EntityReference refToPrincipal, System.Data.Entity.Core.Objects.Internal.IEntityWrapper wrappedPrincipal)

System.Data.Entity.Core.Objects.EntityEntry.FixupEntityReferenceToPrincipal(System.Data.Entity.Core.Objects.DataClasses.EntityReference relatedEnd, System.Data.Entity.Core.EntityKey foreignKey, bool setIsLoaded, bool replaceExistingRef)

System.Data.Entity.Core.Objects.EntityEntry.FixupReferencesByForeignKeys(bool replaceAddedRefs)

System.Data.Entity.Core.Objects.ObjectStateManager.FixupReferencesByForeignKeys(System.Data.Entity.Core.Objects.EntityEntry newEntry, bool replaceAddedRefs)

System.Data.Entity.Core.Objects.ObjectStateManager.FixupKey(System.Data.Entity.Core.Objects.EntityEntry entry)

System.Data.Entity.Core.Objects.EntityEntry.AcceptChanges()

System.Data.Entity.Core.Objects.ObjectContext.AcceptAllChanges()

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

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

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 is also broken in EF5, so it's not a regression

Commented Issue: Exponentially deteriorating performance when using Identity columns in SQL Server Compact 4.0 and Code First [857]

$
0
0
When using Database generated keys with EF Code First and SQL Server Compact 4.0 performance is bad to begin with, but deteriorates exponentially when the table grows. A proof of concept has been published on [Stackoverflow ](http://stackoverflow.com/questions/14768394/exponentially-deteriorating-performance-on-inserts-in-sql-server-compact-4-0-tab#comment20681665_14768394 )and has been confirmed by ErikEJ.
Comments: Blog post published: http://erikej.blogspot.com/2013/02/fix-for-entity-framework-poor-insert.html

Commented Issue: DbMigrations: RenameTable doesn't rename PK or FK [489]

$
0
0
Using DbMigrations on a code first project (c#, 4.5, SQL Server 2012), I've just encountered an error following a table rename operation. This passed validation, but produced an error on the SqlCommand. Steps to reproduce:

1) Create a table called dbo.Foos with columns (id1, id2 and id3) make id1 the Primary key and id3 a Foreign key and add a migration.
3) Run the migration
4) Rename the table in code to dbo.Foo and add a migration
5) Run the migration
6) Alter the Primary key to be both id1 and id2: table.HasKey(new{id1,id2}); and add a migration
7) Attempt to run the migration

Error is produced as the table rename operation in step 4 did not rename the keys!

System.Data.SqlClient.SqlException (0x80131904): 'PK_dbo.Foo' is not a constraint.
Could not drop constraint.

Comments: I've just hit this, I renamed a table which did not rename the PK or FKs, and now adding a table with the same name I am getting errors that the FK object exists.

Commented Issue: DbMigrations: RenameTable doesn't rename PK or FK [489]

$
0
0
Using DbMigrations on a code first project (c#, 4.5, SQL Server 2012), I've just encountered an error following a table rename operation. This passed validation, but produced an error on the SqlCommand. Steps to reproduce:

1) Create a table called dbo.Foos with columns (id1, id2 and id3) make id1 the Primary key and id3 a Foreign key and add a migration.
3) Run the migration
4) Rename the table in code to dbo.Foo and add a migration
5) Run the migration
6) Alter the Primary key to be both id1 and id2: table.HasKey(new{id1,id2}); and add a migration
7) Attempt to run the migration

Error is produced as the table rename operation in step 4 did not rename the keys!

System.Data.SqlClient.SqlException (0x80131904): 'PK_dbo.Foo' is not a constraint.
Could not drop constraint.

Comments: Also, if this is still an issue I suggest bumping up the impact... anyone that renames a table is potentially going to be in for a world of pain down the track.

Edited Issue: DbContext: Expose UseCSharpNullComparisonBehavior [145]

$
0
0
**Talk to Diego or Arthur before doing this**

"Addressing the mismatch in null comparisions between LINQ to Entities and LINQ to Objects is one of the top customers asks we have heard. An example of the issues is that the following query returns empty results although there are Products with null CategoryId:

```
int? cid = null;
var q =
from p in db.Products
where p.CategoryId == cid
select p;
var count = q.Count();
```

The workaround is to explicitly add comparisons for a null constant in the query. When LINQ to Entities sees a comparision against a null constants, i.e. 'a == null' it translates it into a DbExpression with the meaning 'a IS NULL' for the server query.

We added a fix but the new behavior requires setting a flag in ObjectContextOptions which is off by default for compatibility. The change was extensively tested at the time for its impact in query translation and performance, and the plan was always to enable the falg by default in DbContext during initialization of ObjectContext but we missed making the change in DbContext.

This is the main improvement in LINQ to Entities in EF 5 besides performance.

We discovered that setting the flag breaks simple queries in SQL Compact--details in email below. Considering this bug blocked for now.

We have encountered an issue using EF in .NET 4.5 with SQL Compact. This seems like a bug in either SQL Compact itself or in the EF provider for SQL Compact.

Details: we have introduced a new option in ObjectContext.ContextOptions that changes the way nulls are compared in queries generated by LINQ to Entities. A simple example is:

objectContext.ContextOptions.UseCSharpNullComparisonBehavior = true;

var bar = ""bar"";
objectContext.CreateObjectSet<Foo>().Any(f => f.Bar == bar);

where Foo is the only entity type in the model and looks like this:


public class Foo
{
public int Id { get; set; }
public string Bar { get; set; }
}

When we run this against SQL Compact 4.0 in recent Visual Studio 11 Beta builds the SQL generated by the SQL Compact EF provider is as follows:



SELECT
CASE WHEN ( EXISTS (SELECT
1 AS [C1]
FROM [Foos] AS [Extent1]
WHERE (([Extent1].[Bar] = @p__linq__0) AND ( NOT (([Extent1].[Bar] IS NULL) OR (@p__linq__0 IS NULL)))) OR (([Extent1].[Bar] IS NULL) AND (@p__linq__0 IS NULL))
)) THEN cast(1 as bit) WHEN ( NOT EXISTS (SELECT
1 AS [C1]
FROM [Foos] AS [Extent2]
WHERE (([Extent2].[Bar] = @p__linq__0) AND ( NOT (([Extent2].[Bar] IS NULL) OR (@p__linq__0 IS NULL)))) OR (([Extent2].[Bar] IS NULL) AND (@p__linq__0 IS NULL))
)) THEN cast(0 as bit) END AS [C1]
FROM ( SELECT 1 AS X ) AS [SingleRowTable1]

This fails with the following exception:

System.Data.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details.

System.Data.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> System.Data.SqlServerCe.SqlCeException: The specified argument value for the function is not valid. [ Argument # = 1,Name of function(if known) = isnull ]

at System.Data.SqlServerCe.SqlCeCommand.ProcessResults(Int32 hr)

at System.Data.SqlServerCe.SqlCeCommand.CompileQueryPlan()

at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options)

at System.Data.SqlServerCe.SqlCeCommand.ExecuteReader(CommandBehavior behavior)

at System.Data.SqlServerCe.SqlCeMultiCommand.ExecuteReader(CommandBehavior behavior)

at System.Data.SqlServerCe.SqlCeMultiCommand.ExecuteDbDataReader(CommandBehavior behavior)

at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)

at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

--- End of inner exception stack trace ---

at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)

at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)

at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()

at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)

at System.Data.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__3[TResult](IEnumerable`1 sequence)

at System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)

at System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression)

Data\Entity\Internal\Linq\DbQueryProvider.cs(82,0): at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression)

at System.Linq.Queryable.Any[TSource](IQueryable`1 source, Expression`1 predicate)

ProductivityApi\SimpleScenariosForSqlCe.cs(351,0): at ProductivityApiTests.SimpleScenariosForSqlCe.Can_perform_simple_Any_query_in_SqlCe()



We get the same exception when trying to execute the generated SQL outside of EF. In addition, we can also reproduce this exception using Entity SQL even without the changes for the new flag. For example:



using (SqlCeIssueEntities ctx = new SqlCeIssueEntities())

{

var queryString = @""select value c from SqlCeIssueEntities.Tests as c where @myVar is null or c.name = @myVar"";

ObjectQuery<Test> contactQuery = new ObjectQuery<Test>(queryString, ctx);



contactQuery.Parameters.Add(new ObjectParameter(""myVar"", ""TestVal""));



foreach (Test result in contactQuery)

Console.WriteLine(""Last Name: {0};"", result.name);

}"

See http://entityframework.codeplex.com/workitem/287 for more details on teh underlying issue.

Edited Issue: DbContext: Expose UseCSharpNullComparisonBehavior [145]

$
0
0
**Talk to Diego or Arthur before doing this**

"Addressing the mismatch in null comparisions between LINQ to Entities and LINQ to Objects is one of the top customers asks we have heard. An example of the issues is that the following query returns empty results although there are Products with null CategoryId:

```
int? cid = null;
var q =
from p in db.Products
where p.CategoryId == cid
select p;
var count = q.Count();
```

The workaround is to explicitly add comparisons for a null constant in the query. When LINQ to Entities sees a comparision against a null constants, i.e. 'a == null' it translates it into a DbExpression with the meaning 'a IS NULL' for the server query.

We added a fix but the new behavior requires setting a flag in ObjectContextOptions which is off by default for compatibility. The change was extensively tested at the time for its impact in query translation and performance, and the plan was always to enable the falg by default in DbContext during initialization of ObjectContext but we missed making the change in DbContext.

This is the main improvement in LINQ to Entities in EF 5 besides performance.

We discovered that setting the flag breaks simple queries in SQL Compact--details in email below. Considering this bug blocked for now.

We have encountered an issue using EF in .NET 4.5 with SQL Compact. This seems like a bug in either SQL Compact itself or in the EF provider for SQL Compact.

Details: we have introduced a new option in ObjectContext.ContextOptions that changes the way nulls are compared in queries generated by LINQ to Entities. A simple example is:

```
objectContext.ContextOptions.UseCSharpNullComparisonBehavior = true;

var bar = ""bar"";
objectContext.CreateObjectSet<Foo>().Any(f => f.Bar == bar);
```

where Foo is the only entity type in the model and looks like this:

```
public class Foo
{
public int Id { get; set; }
public string Bar { get; set; }
}
```

When we run this against SQL Compact 4.0 in recent Visual Studio 11 Beta builds the SQL generated by the SQL Compact EF provider is as follows:

```
SELECT
CASE WHEN ( EXISTS (SELECT
1 AS [C1]
FROM [Foos] AS [Extent1]
WHERE (([Extent1].[Bar] = @p__linq__0) AND ( NOT (([Extent1].[Bar] IS NULL) OR (@p__linq__0 IS NULL)))) OR (([Extent1].[Bar] IS NULL) AND (@p__linq__0 IS NULL))
)) THEN cast(1 as bit) WHEN ( NOT EXISTS (SELECT
1 AS [C1]
FROM [Foos] AS [Extent2]
WHERE (([Extent2].[Bar] = @p__linq__0) AND ( NOT (([Extent2].[Bar] IS NULL) OR (@p__linq__0 IS NULL)))) OR (([Extent2].[Bar] IS NULL) AND (@p__linq__0 IS NULL))
)) THEN cast(0 as bit) END AS [C1]
FROM ( SELECT 1 AS X ) AS [SingleRowTable1]
```

This fails with the following exception:

```
System.Data.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details.

System.Data.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> System.Data.SqlServerCe.SqlCeException: The specified argument value for the function is not valid. [ Argument # = 1,Name of function(if known) = isnull ]

at System.Data.SqlServerCe.SqlCeCommand.ProcessResults(Int32 hr)

at System.Data.SqlServerCe.SqlCeCommand.CompileQueryPlan()

at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options)

at System.Data.SqlServerCe.SqlCeCommand.ExecuteReader(CommandBehavior behavior)

at System.Data.SqlServerCe.SqlCeMultiCommand.ExecuteReader(CommandBehavior behavior)

at System.Data.SqlServerCe.SqlCeMultiCommand.ExecuteDbDataReader(CommandBehavior behavior)

at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)

at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

--- End of inner exception stack trace ---

at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)

at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)

at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()

at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)

at System.Data.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__3[TResult](IEnumerable`1 sequence)

at System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)

at System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression)

Data\Entity\Internal\Linq\DbQueryProvider.cs(82,0): at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression)

at System.Linq.Queryable.Any[TSource](IQueryable`1 source, Expression`1 predicate)

ProductivityApi\SimpleScenariosForSqlCe.cs(351,0): at ProductivityApiTests.SimpleScenariosForSqlCe.Can_perform_simple_Any_query_in_SqlCe()

```

We get the same exception when trying to execute the generated SQL outside of EF. In addition, we can also reproduce this exception using Entity SQL even without the changes for the new flag. For example:


```
using (SqlCeIssueEntities ctx = new SqlCeIssueEntities())
{
var queryString = @""select value c from SqlCeIssueEntities.Tests as c where @myVar is null or c.name = @myVar"";

ObjectQuery<Test> contactQuery = new ObjectQuery<Test>(queryString, ctx);
contactQuery.Parameters.Add(new ObjectParameter(""myVar"", ""TestVal""));
foreach (Test result in contactQuery)
Console.WriteLine(""Last Name: {0};"", result.name);
}
```
See http://entityframework.codeplex.com/workitem/287 for more details on the underlying issue.

Edited Issue: DbContext: Expose UseCSharpNullComparisonBehavior [145]

$
0
0
**Talk to Diego or Arthur before doing this**

"Addressing the mismatch in null comparisions between LINQ to Entities and LINQ to Objects is one of the top customers asks we have heard. An example of the issues is that the following query returns empty results although there are Products with null CategoryId:

```
int? cid = null;
var q =
from p in db.Products
where p.CategoryId == cid
select p;
var count = q.Count();
```

The workaround is to explicitly add comparisons for a null constant in the query. When LINQ to Entities sees a comparision against a null constants, i.e. 'a == null' it translates it into a DbExpression with the meaning 'a IS NULL' for the server query.

We added a fix but the new behavior requires setting a flag in ObjectContextOptions which is off by default for compatibility. The change was extensively tested at the time for its impact in query translation and performance, and the plan was always to enable the falg by default in DbContext during initialization of ObjectContext but we missed making the change in DbContext.

This is the main improvement in LINQ to Entities in EF 5 besides performance.

We discovered that setting the flag breaks simple queries in SQL Compact--details in email below. Considering this bug blocked for now.

We have encountered an issue using EF in .NET 4.5 with SQL Compact. This seems like a bug in either SQL Compact itself or in the EF provider for SQL Compact.

Details: we have introduced a new option in ObjectContext.ContextOptions that changes the way nulls are compared in queries generated by LINQ to Entities. A simple example is:

```
objectContext.ContextOptions.UseCSharpNullComparisonBehavior = true;

var bar = ""bar"";
objectContext.CreateObjectSet<Foo>().Any(f => f.Bar == bar);
```

where Foo is the only entity type in the model and looks like this:

```
public class Foo
{
public int Id { get; set; }
public string Bar { get; set; }
}
```

When we run this against SQL Compact 4.0 in recent Visual Studio 11 Beta builds the SQL generated by the SQL Compact EF provider is as follows:

```
SELECT
CASE WHEN ( EXISTS (SELECT
1 AS [C1]
FROM [Foos] AS [Extent1]
WHERE (([Extent1].[Bar] = @p__linq__0) AND ( NOT (([Extent1].[Bar] IS NULL) OR (@p__linq__0 IS NULL)))) OR (([Extent1].[Bar] IS NULL) AND (@p__linq__0 IS NULL))
)) THEN cast(1 as bit) WHEN ( NOT EXISTS (SELECT
1 AS [C1]
FROM [Foos] AS [Extent2]
WHERE (([Extent2].[Bar] = @p__linq__0) AND ( NOT (([Extent2].[Bar] IS NULL) OR (@p__linq__0 IS NULL)))) OR (([Extent2].[Bar] IS NULL) AND (@p__linq__0 IS NULL))
)) THEN cast(0 as bit) END AS [C1]
FROM ( SELECT 1 AS X ) AS [SingleRowTable1]
```

This fails with the following exception:

```
System.Data.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details.

System.Data.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> System.Data.SqlServerCe.SqlCeException: The specified argument value for the function is not valid. [ Argument # = 1,Name of function(if known) = isnull ]

at System.Data.SqlServerCe.SqlCeCommand.ProcessResults(Int32 hr)

at System.Data.SqlServerCe.SqlCeCommand.CompileQueryPlan()

at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options)

at System.Data.SqlServerCe.SqlCeCommand.ExecuteReader(CommandBehavior behavior)

at System.Data.SqlServerCe.SqlCeMultiCommand.ExecuteReader(CommandBehavior behavior)

at System.Data.SqlServerCe.SqlCeMultiCommand.ExecuteDbDataReader(CommandBehavior behavior)

at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)

at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

--- End of inner exception stack trace ---

at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)

at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)

at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()

at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)

at System.Data.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__3[TResult](IEnumerable`1 sequence)

at System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)

at System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression)

Data\Entity\Internal\Linq\DbQueryProvider.cs(82,0): at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression)

at System.Linq.Queryable.Any[TSource](IQueryable`1 source, Expression`1 predicate)

ProductivityApi\SimpleScenariosForSqlCe.cs(351,0): at ProductivityApiTests.SimpleScenariosForSqlCe.Can_perform_simple_Any_query_in_SqlCe()

```

We get the same exception when trying to execute the generated SQL outside of EF. In addition, we can also reproduce this exception using Entity SQL even without the changes for the new flag. For example:


```
using (SqlCeIssueEntities ctx = new SqlCeIssueEntities())
{
var queryString = @""select value c from SqlCeIssueEntities.Tests as c where @myVar is null or c.name = @myVar"";

ObjectQuery<Test> contactQuery = new ObjectQuery<Test>(queryString, ctx);
contactQuery.Parameters.Add(new ObjectParameter(""myVar"", ""TestVal""));
foreach (Test result in contactQuery)
Console.WriteLine(""Last Name: {0};"", result.name);
}
```
See http://entityframework.codeplex.com/workitem/287 for more details on the underlying issue.

Edited Issue: DbContext with open connection does not work with TransactionScope [771]

$
0
0
When trying to use DbContext that uses connection that has already been opened in the TransactionScope, we get exception:
MSDTC on server 'ServerName' is unavailable.

Same scenario works when using ObjectContext or a closed connection. Also, the scenario works if we disable DatabaseInitializer. Scenario also works if the connection already contains the "Application Name=EntityFrameworkMUE" cookie. Apparently we mess up with the connection during database initialization, which causes promotion to a distributed transaction and hence the error.

Here is the repro:

var connectionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=TransactionET;Integrated Security=SSPI;MultipleActiveResultSets=True;";
var sqlConnection = new SqlConnection(connectionString);
using (var ts = new TransactionScope())
{
sqlConnection.Open();

using (var ctx = new TransactionContext(sqlConnection, contextOwnsConnection: false))
{
var blog = new Blog
{
Title = "My Blog",
};

ctx.Blogs.Add(blog);
ctx.SaveChanges();
}
}


Commented Issue: DbContext with open connection does not work with TransactionScope [771]

$
0
0
When trying to use DbContext that uses connection that has already been opened in the TransactionScope, we get exception:
MSDTC on server 'ServerName' is unavailable.

Same scenario works when using ObjectContext or a closed connection. Also, the scenario works if we disable DatabaseInitializer. Scenario also works if the connection already contains the "Application Name=EntityFrameworkMUE" cookie. Apparently we mess up with the connection during database initialization, which causes promotion to a distributed transaction and hence the error.

Here is the repro:

var connectionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=TransactionET;Integrated Security=SSPI;MultipleActiveResultSets=True;";
var sqlConnection = new SqlConnection(connectionString);
using (var ts = new TransactionScope())
{
sqlConnection.Open();

using (var ctx = new TransactionContext(sqlConnection, contextOwnsConnection: false))
{
var blog = new Blog
{
Title = "My Blog",
};

ctx.Blogs.Add(blog);
ctx.SaveChanges();
}
}

Comments: I believe we removed the code that introduced "MUE" for the application attribute of the connection string. We should validate if the issue is gone.

Edited Feature: Auto compile enhancement - allow passing of a delegate to perform hashing [263]

$
0
0
During a customer test of the new auto-compile feature of EF 5 (prerelease build) was tested and compared with the implementation the CAT team built for the custoemr using a wrapping provider.

What we discovered was promising. Performance with the EF autocompile was close to that of the wrapping provider. This is great because previous tests and subsequent code profiling/refinement showed that the EF auto-compile was once much slower.

We implemented data caching with the new EF 5.0 and discovered that this caching was 2x slower using the EF provider. The reason is simple, we generated a hash of the T-SQL as opposed to the expression tree.

Thus, if EF allowed the user to pass in their own hashing delegate for autocompile then this same hash could be used for the data caching as well. Or

Provide a mechanism upon which extract the hash key from the auto-compile whereby the user could perform a data cache lookup in advance to running the query.


Edited Feature: Permit the ability to marked specific entities as 'unmanaged' by the ORM [262]

$
0
0
Is there some way to mark specific entities to not be managed by the OSM at all? No - it must be via turning change tracking off for an entire set of entities. Enable a mechanism upon which to mark specific entities as 'unmanaged' or untracked by the ORM.

Commented Feature: Enable a mechanism to provide query hints [261]

$
0
0
Neither the Linq extensions to C# nor Entity Framework provides any way to pass a query hint to the underlying data provider. For database programming, this is a fundamental shortcoming of the Microsoft development stack. There is no way, on a per-query basis to pass a simple locking hint (NOLOCK, HOLDLOCK, etc.).
The only workaround is to use TransactionScope objects to fence specific code boundaries, which essentially executes SET ISOLATION statements on the connection. But there is no way, for example, to specify READPAST or FORCESEEK query options, which are essential to managing lock contention in high-volume systems. Obviously, this also means there is no way to provide index hints.

Short Term: Add a monadic With() function to Entity Framework to transmit query hints to Sql Server:
(from e in Db.ExtCompany.With(QueryHint.ReadPast) where e.Company == companyId select e).Any();

Longer Term: Add a “with” keyword to C# for use in Linq to supply a query-provider-specific hint to the underlying provider:
(from e in Db.ExtCompany with ReadPast, ForceSeek where e.Company == companyId select e).Any();


Comments: **EF Team Triage:** We agree that this would be a good scenario to enable. Taking into account where we are in the EF6 release along with the size and the impact of this feature our team is not planning to implement it in EF6. Therefore, we are moving it to the Future release to reconsider in the next release.

Edited Feature: Support Anonymous Types as output for Compiled Queries [260]

$
0
0
Anonymous types are the only means for an EF developer to project the results of a query into an object other than the native entity. For queries that join multiple tables, the result set includes all columns from all tables, which is very, very rarely the intention

Unfortunately, anonymous types are not supported for compiled queries.

Commented Issue: Database first: Consider improving experience when key metadata is missing [778]

$
0
0
Currently when metadata about the key of a database object is missing we use a heuristic to infer a synthetic key. This mechanism usually comes up with something that doesn't match user expectations and/or doesn't align with the actual data and or schema present in the database. We have had a lot of feedback over time about several problems that the current mechanism has:

1. Users find it very hard to understand what just happened
2. We reason about nullability but we fail to consider other aspects that may make a column unsuitable as a key, such as order comparability, e.g. spatial types shouldn't be ever part of a key
3. We have had reports that the behavior can effectively be random, e.g. going through the process may result in different outcomes each time
4. As with many other things, once you have carefully picked the right set of columns for the key, updating the model from the database will overwrite your choice, which can be very annoying.

I don't have a specific idea on how to improve this other than stop doing key inference altogether and instead allow an invalid model to be generated and useful warnings to be shown.
Comments: For 2) the problem is that the method that tells if a column could be used as a key property was not updated when we added support for spatial and allowed any colum but binary in EF1. This should be fixed in the new designer.

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: Update: Brice recognized that the previous iteration introduced a race condition which would have allowed an app to use configuration before it was properly configured. Second iteration changes EnsureLoadedForContext to only create the type rather than the instance such that the change that introduced the race condition is not now needed.

Created Feature: Code First: Improve fluency of entity configuration APIs [887]

$
0
0
Some of the methods on EntityTypeConfiguration aren't chain-able. I.e. ToTable, Ignore.


Created Feature: Consider creating IDbDependencyResolver service to obtain current transaction [888]

$
0
0
This was suggested on a discussion thread from the design meeting notes:
http://entityframework.codeplex.com/wikipage?title=Design%20Meeting%20Notes%20-%20February%207%2c%202013

This could potentially make it easier to configure EF to use the transactions that you want EF to use without having to call UseTransaction (or similar) wherever the context instance is created.

We would need to figure out when to call into the service and how to handle the lifetime of the returned object.

Created Feature: Code First: Add nested closure overload to Property API [889]

$
0
0
Sometimes it would be nice if you could do:

modelBuilder
.Entity<OrderLine>(ec =>
{
ec.Property();
ec.Property();
// etc.
});

Edited Feature: Code First: Add nested closure overload to Property API [889]

$
0
0
Sometimes it would be nice if you could do:

modelBuilder
.Entity<OrderLine>(ec =>
{
ec.Property();
ec.Property();
// etc.
});

Created Issue: Designer: Consider renaming 'ADO.NET Entity Data Model' [890]

$
0
0
When adding a new model folks need to select 'ADO.NET Entity Data Model'. We should consider renaming this to 'Entity Framework Model'.

An alternative is to provide a second option and leave the 'ADO.NET Entity Data Model' item in place to reduce confusion and not break existing walkthroughs etc.
Viewing all 9566 articles
Browse latest View live


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