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

Closed Unassigned: EF 6.1.2 generate incorrect sql [2694]

$
0
0
I was using EF 6.1.1 in my projects with mysql connector .net 6.9.5. After updating to EF 6.1.2 some queries generate exceptions of type

System.Data.Entity.Core.EntityCommandExecutionException.
```
{"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM ((SELECT\r\nFROM ((SELECT\r\n`GroupBy1`.`K1` AS `PRODUCTO`, \r\n(CASE WHEN (1 = 1' at line 47"}
```

I don't know if are caused for a problem with mysql connector. But as it failed after EF update i'm here asking.

Queries on wich exceptions are thrown are so large. And i don't know if it is enough to provide only generated SQL queries.

Please, see attached files. One is SQL generated with EF 6.1.1 and the other one with 6.1.2.

Thanks.

__Edit__: This generated queries are the result of some IQueryable<T> methods, if I change to IEnumerable<T> the first method everything goes OK again. And another queries using IEnumerable<T> throws same exeption type but inner exception is:
```
{"Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding."}
```
Comments: I am going ahead resolving this as duplicate of https://entityframework.codeplex.com/workitem/2651. It can be reactivated if the issue persists after upgrading to 6.1.3 RTM.

Edited Issue: EF 6.1.2 generate incorrect sql [2694]

$
0
0
I was using EF 6.1.1 in my projects with mysql connector .net 6.9.5. After updating to EF 6.1.2 some queries generate exceptions of type

System.Data.Entity.Core.EntityCommandExecutionException.
```
{"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM ((SELECT\r\nFROM ((SELECT\r\n`GroupBy1`.`K1` AS `PRODUCTO`, \r\n(CASE WHEN (1 = 1' at line 47"}
```

I don't know if are caused for a problem with mysql connector. But as it failed after EF update i'm here asking.

Queries on wich exceptions are thrown are so large. And i don't know if it is enough to provide only generated SQL queries.

Please, see attached files. One is SQL generated with EF 6.1.1 and the other one with 6.1.2.

Thanks.

__Edit__: This generated queries are the result of some IQueryable<T> methods, if I change to IEnumerable<T> the first method everything goes OK again. And another queries using IEnumerable<T> throws same exeption type but inner exception is:
```
{"Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding."}
```

Edited Unassigned: Set isolation level [2685]

$
0
0
I wanted to do the following using sqlserver 2014:
_dbContext.Database.ExecuteSqlCommand("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;");

It runs ok, but the selects after it doesn't read the uncomited data, if I use it on management studio, works fine, but when I do it on DbContext, it doesnt.

I can use transaction scope, but, I wanted all the selects made, to bring-me uncommited data. I know it's not the best of the worlds, but is something we need on our application.

Thanks

Commented Unassigned: Have a custom .NET method translate to arbitrary T-SQL expression [2660]

$
0
0
A LINQ Where() predicate should be able to translate into a T-SQL expression so that MS SQL Server can execute a custom expression (e. g. UDF) from having a .NET representation in code.

This is particularly useful for developers of EF add-ons and frameworks based on EF.


The following setup, focussing on function __F::f()__

```
public class MyContext : DbContext
{
public DbSet<Order> Orders { get; set; }
}


static public class F
{
static public void f(EdmFunction edmFunc, Func<Order, string> member, params object[] args)
{
... // edmFunc is supposed to be set with appropriate values here.
... // That's the sole purpose of "f".
}


static public void Main()
{
using (MyContext ctx = new MyContext())
{
var x = from a in ctx.Orders.Where(f, o => o.Name)
select a;
}
}
}

```

... should be able to translate into T-SQL, resulting in T-SQL similar to this:

```
SELECT * FROM Orders WHERE dbo.fx(Orders.Name) = 1
```
(whereby __"dbo.fx(" + Order.Name + ") = 1"__ be the expression generated from F::f() )



This would also allow to manually extend EF for SQL Server predicates not currently supported, like CONTAINS() or FREETEXT(), by creating an MethodCallExpression within F::f() that would result in T-SQL like:

```
SELECT * FROM Orders WHERE CONTAINS(Orders.Name, 'foo')
```

That would require the following to be possible:

```
static public class F
{
static public void f(EdmFunction edmFunc, Func<Order, string> member, params object[] args)
{
... // edmFunc is supposed to be set with appropriate values here.
... // That's the sole purpose of "f".
}


static public void Main()
{
using (MyContext ctx = new MyContext())
{
var x = from a in ctx.Orders.Where(f, o => o.Name, "foo")
select a;
}
}
}
```


.

The declaration of the suggested Entity Framework Where() function would be similar to this:

```
public static IQueryable<TSource> Where<TSource, TMembers>
( this IQueryable<TSource> source
, Action<EdmFunction, Func<TSource, TMembers>>, params object[]> func
, Func<TSource, TMembers> members
, params object[] args
);
```
... or:

```
public static IQueryable<TSource> Where<TSource, TMembers, TParams>
( this IQueryable<TSource> source
, Action<EdmFunction, Func<TSource, TMembers>>, TParams> func
, Func<TSource, TMembers> members
, TParams args
);
```
Comments: @settrend: Sorry if this has been sitting on my list for a long time. To try to answer your question: I the problem is that Contains() and FreeText() are SQL Server predicate expression and not proper functions EF can support. The one thing that set them apart is that some of the arguments for them are database object names, e.g. the first argument for Contains() is a column name. You should be able to workaround that by creating a proper Table-Valued Function in your database, e.g.: ``` CREATE FUNCTION ProductsContains ( @keyword nvarchar(40) ) RETURNS TABLE AS RETURN ( select * from dbo.Products where CONTAINS(Description, @keyword) ) GO ``` Then you should be able to map this function using @moozzyk's CodeFirstFunctions.

Edited Unassigned: Have a custom .NET method translate to arbitrary T-SQL expression [2660]

$
0
0
A LINQ Where() predicate should be able to translate into a T-SQL expression so that MS SQL Server can execute a custom expression (e. g. UDF) from having a .NET representation in code.

This is particularly useful for developers of EF add-ons and frameworks based on EF.


The following setup, focussing on function __F::f()__

```
public class MyContext : DbContext
{
public DbSet<Order> Orders { get; set; }
}


static public class F
{
static public void f(EdmFunction edmFunc, Func<Order, string> member, params object[] args)
{
... // edmFunc is supposed to be set with appropriate values here.
... // That's the sole purpose of "f".
}


static public void Main()
{
using (MyContext ctx = new MyContext())
{
var x = from a in ctx.Orders.Where(f, o => o.Name)
select a;
}
}
}

```

... should be able to translate into T-SQL, resulting in T-SQL similar to this:

```
SELECT * FROM Orders WHERE dbo.fx(Orders.Name) = 1
```
(whereby __"dbo.fx(" + Order.Name + ") = 1"__ be the expression generated from F::f() )



This would also allow to manually extend EF for SQL Server predicates not currently supported, like CONTAINS() or FREETEXT(), by creating an MethodCallExpression within F::f() that would result in T-SQL like:

```
SELECT * FROM Orders WHERE CONTAINS(Orders.Name, 'foo')
```

That would require the following to be possible:

```
static public class F
{
static public void f(EdmFunction edmFunc, Func<Order, string> member, params object[] args)
{
... // edmFunc is supposed to be set with appropriate values here.
... // That's the sole purpose of "f".
}


static public void Main()
{
using (MyContext ctx = new MyContext())
{
var x = from a in ctx.Orders.Where(f, o => o.Name, "foo")
select a;
}
}
}
```


.

The declaration of the suggested Entity Framework Where() function would be similar to this:

```
public static IQueryable<TSource> Where<TSource, TMembers>
( this IQueryable<TSource> source
, Action<EdmFunction, Func<TSource, TMembers>>, params object[]> func
, Func<TSource, TMembers> members
, params object[] args
);
```
... or:

```
public static IQueryable<TSource> Where<TSource, TMembers, TParams>
( this IQueryable<TSource> source
, Action<EdmFunction, Func<TSource, TMembers>>, TParams> func
, Func<TSource, TMembers> members
, TParams args
);
```

Commented Unassigned: Have a custom .NET method translate to arbitrary T-SQL expression [2660]

$
0
0
A LINQ Where() predicate should be able to translate into a T-SQL expression so that MS SQL Server can execute a custom expression (e. g. UDF) from having a .NET representation in code.

This is particularly useful for developers of EF add-ons and frameworks based on EF.


The following setup, focussing on function __F::f()__

```
public class MyContext : DbContext
{
public DbSet<Order> Orders { get; set; }
}


static public class F
{
static public void f(EdmFunction edmFunc, Func<Order, string> member, params object[] args)
{
... // edmFunc is supposed to be set with appropriate values here.
... // That's the sole purpose of "f".
}


static public void Main()
{
using (MyContext ctx = new MyContext())
{
var x = from a in ctx.Orders.Where(f, o => o.Name)
select a;
}
}
}

```

... should be able to translate into T-SQL, resulting in T-SQL similar to this:

```
SELECT * FROM Orders WHERE dbo.fx(Orders.Name) = 1
```
(whereby __"dbo.fx(" + Order.Name + ") = 1"__ be the expression generated from F::f() )



This would also allow to manually extend EF for SQL Server predicates not currently supported, like CONTAINS() or FREETEXT(), by creating an MethodCallExpression within F::f() that would result in T-SQL like:

```
SELECT * FROM Orders WHERE CONTAINS(Orders.Name, 'foo')
```

That would require the following to be possible:

```
static public class F
{
static public void f(EdmFunction edmFunc, Func<Order, string> member, params object[] args)
{
... // edmFunc is supposed to be set with appropriate values here.
... // That's the sole purpose of "f".
}


static public void Main()
{
using (MyContext ctx = new MyContext())
{
var x = from a in ctx.Orders.Where(f, o => o.Name, "foo")
select a;
}
}
}
```


.

The declaration of the suggested Entity Framework Where() function would be similar to this:

```
public static IQueryable<TSource> Where<TSource, TMembers>
( this IQueryable<TSource> source
, Action<EdmFunction, Func<TSource, TMembers>>, params object[]> func
, Func<TSource, TMembers> members
, params object[] args
);
```
... or:

```
public static IQueryable<TSource> Where<TSource, TMembers, TParams>
( this IQueryable<TSource> source
, Action<EdmFunction, Func<TSource, TMembers>>, TParams> func
, Func<TSource, TMembers> members
, TParams args
);
```
Comments: Clearing up fields to bring to next triage. I am hoping I have answered the last question and we can close. Just not sure what is the most appropriate resolution.

Commented Unassigned: Have a custom .NET method translate to arbitrary T-SQL expression [2660]

$
0
0
A LINQ Where() predicate should be able to translate into a T-SQL expression so that MS SQL Server can execute a custom expression (e. g. UDF) from having a .NET representation in code.

This is particularly useful for developers of EF add-ons and frameworks based on EF.


The following setup, focussing on function __F::f()__

```
public class MyContext : DbContext
{
public DbSet<Order> Orders { get; set; }
}


static public class F
{
static public void f(EdmFunction edmFunc, Func<Order, string> member, params object[] args)
{
... // edmFunc is supposed to be set with appropriate values here.
... // That's the sole purpose of "f".
}


static public void Main()
{
using (MyContext ctx = new MyContext())
{
var x = from a in ctx.Orders.Where(f, o => o.Name)
select a;
}
}
}

```

... should be able to translate into T-SQL, resulting in T-SQL similar to this:

```
SELECT * FROM Orders WHERE dbo.fx(Orders.Name) = 1
```
(whereby __"dbo.fx(" + Order.Name + ") = 1"__ be the expression generated from F::f() )



This would also allow to manually extend EF for SQL Server predicates not currently supported, like CONTAINS() or FREETEXT(), by creating an MethodCallExpression within F::f() that would result in T-SQL like:

```
SELECT * FROM Orders WHERE CONTAINS(Orders.Name, 'foo')
```

That would require the following to be possible:

```
static public class F
{
static public void f(EdmFunction edmFunc, Func<Order, string> member, params object[] args)
{
... // edmFunc is supposed to be set with appropriate values here.
... // That's the sole purpose of "f".
}


static public void Main()
{
using (MyContext ctx = new MyContext())
{
var x = from a in ctx.Orders.Where(f, o => o.Name, "foo")
select a;
}
}
}
```


.

The declaration of the suggested Entity Framework Where() function would be similar to this:

```
public static IQueryable<TSource> Where<TSource, TMembers>
( this IQueryable<TSource> source
, Action<EdmFunction, Func<TSource, TMembers>>, params object[]> func
, Func<TSource, TMembers> members
, params object[] args
);
```
... or:

```
public static IQueryable<TSource> Where<TSource, TMembers, TParams>
( this IQueryable<TSource> source
, Action<EdmFunction, Func<TSource, TMembers>>, TParams> func
, Func<TSource, TMembers> members
, TParams args
);
```
Comments: Thank you for taking the time to follow this issue. Yes, as we currently don't have another option, this is the only way of getting things to work at the moment. But it has a significant drawback, though: We can't use the predicate in the original statement. Instead we have to join the full results of the original statement with the results from the TVF, which has an extraordinary negative impact on performance. Given an example that we're targeting to create an add-in to support full-text in Entity Framework, our goal was to provide an interface like this: ``` var selection1 = ctx.Blogs.Where(b => Functions.Contains("FORMSOF (INFLECTIONAL, throws)", b.Content)); var selection2 = ctx.Blogs.Where(b => Functions.Contains("FORMSOF (INFLECTIONAL, throws)", b.Content, b.title)); ``` . __But this interface won't work with the workaround, because for the following reasons:__ . 1. With the workaround in place, we need to additionally provide the table name. . 1. Since we're not able to create UDFs that work on tables dynamically and since we cannot assign columns to the CONTAINS predicate dynamically, we need to provide one TVF per table providing a full-text index plus one TVF per combination of full-text columns within such table. . 1. Then again, because we cannot assign multiple UDFs to the same CodeFirstFunction definition we finally cannot make use of all these different UDFs. So, I'm afraid, the solution doesn't appear to be a workaround for providing a general add-in for built-in predicates.

New Post: XmlComments to ExtendedProperties

$
0
0
Hi,

is it possible to tweak CodeFirst database generation to put the XML comments to the ExtendedProperties of a column?

Regards
L.

New Post: XmlComments to ExtendedProperties

$
0
0
Have a look at the EF Reverse POCO Template on VS Gallery

New Post: XmlComments to ExtendedProperties

$
0
0
Wrong direction. ;)
I want to tweak the generation /TO/ the database not /FROM/.

Commented Feature: Improve reverse engineer when two tables with the same name in different schemas [268]

$
0
0
EF does not support multiple schemas in a database. All entities are created in a default namespace. This means entity name collisions could occur. Entity names are currently appended with a number to represent the next entity added to the model. This means that on systems with a large number of tables, the model must be edited by hand to properly resolve the name into an identifiable label.

A possible mitigation would be to ensure that each entity is placed in a namespace equivalent to the schema name.

SQL Server databases can contain multiple schemas. Each schema can have identically named table and function names. For example, ISVs are deciding to provide multi-tenant services. One mechanism is to provide a schema per customer and each schema would contain the same tables. But EF has not mechanism to enable such name clashes and provide automated name resolution. We are seeing this more and more particularly with customers planning to host their own service in the cloud but ensure they are utilizing the most cost effective measures to do so, ie. one SQL Server/multi-tenant.

Comments: We are looking at this issue not from the multi-tenant perspective. We are going to implement multi tenancy by "partitioning" tables with Tenant key. We are interested at this feature in order to achieve better entity schema separation. Something like Sales.Orders, Retail.Orders, Catalogs.PaymentTypes, Crm.Contacts, etc ... where one EDMX can manage entities from more than one schema and there will be no table naming conflicts (Sales.Orders and Retail.Orders).

Commented Issue: UpForGrabs: A relationship between a class named "Foo" and another named "Foo_Foo" gives the error "The item with identity 'Foo_Foo_Foo' already exists in the metadata collection." [2084]

$
0
0
Using EF 6.0.2 Code First, the names of two classes with a navigation property between them can cause a unwanted comportament.

I've attached a sample application that can reproduce the bug. The EntityFramework package must be installed before building or running.

Apparently a name conflict occurs in some internal dictionary because of the underscore, seems like it is used somehow in the mapping logic.

If the referencing class is renamed from, e.g., "Foo_Foo" to "FooFoo", removing the underscore, the problem disappears.
Comments: Any news regarding a fix for this issue ? Is this issue eventually related to the [Issue 2621](https://entityframework.codeplex.com/workitem/2621) ? Thanks in advance.

Created Unassigned: Seed database with DropCreateDatabaseAlways creates wrongly-named PK column with Table-Per-Hierarchy [2699]

$
0
0
I upgraded from EF 6.1.1 to 6.1.2 using NUGet. I had taken a copy of the DDL generated with 6.1.1 and compared it with 6.1.2 and they are identical. However, when I run my integration tests and seed the database with DropCreateDatabaseAlways, it generates the wrong column name for the PK.

Here is the DDL generated by the EF Power Tools in Visual Studio:

```
create table [dbo].[BusinessEntity] (
[BusinessEntityId] [bigint] not null identity,
...,
primary key ([BusinessEntityId])
);
```

and here is the SQL that was executed when seeding the database:
```
CREATE TABLE [dbo].[BusinessEntity] (
[TrustId] [bigint] NOT NULL IDENTITY,
...
```
BusinessEntity is my abstract base class and Trust is one of its subtypes (there are about ten in all):

```
public abstract class BusinessEntity
{
[Column("Id")]
public virtual Int64 Id { get; protected set; }
}

[Table("BusinessEntity")]
public class Trust : BusinessEntity
{
}
```

I have a naming convention that changes the Id property of my classes to <class>Id. Here it is:

```
/// <summary>
/// Overrides the EF ColumnAttributeConvention so that we can automatically map Id columns as tablenameId.
/// To get this to work, add the Column attribute to your class's Id property: [Column("Id"]. The db
/// column name will then become typeId, eg Id on Person becomes PersonId.
/// </summary>
public class OverrideColumnAttributeConvention : ColumnAttributeConvention
{
private const string IdColumn = "Id";

public override void Apply(ConventionPrimitivePropertyConfiguration configuration, ColumnAttribute attribute)
{
if (attribute.Name.HasValue() && attribute.Name.Equals(IdColumn, StringComparison.InvariantCultureIgnoreCase))
{
var type = configuration.ClrPropertyInfo.ReflectedType;
if (type != null)
{
var columnName = string.Format("{0}{1}", type.Name, attribute.Name);
configuration.HasColumnName(columnName);
configuration.HasColumnOrder(0);
}
}

base.Apply(configuration, attribute);
}
}

```

If I step through the integration test in the debugger, I can see my convention being called and returning the correct PK column name.

Note that this code has all been working fine in 6.1.1 but breaks with 6.1.2.

Edited Unassigned: Seed database with DropCreateDatabaseAlways creates wrongly-named PK column with Table-Per-Hierarchy [2699]

$
0
0
I upgraded from EF 6.1.1 to 6.1.2 using NUGet. I had taken a copy of the DDL generated with 6.1.1 and compared it with 6.1.2 and they are identical. However, when I run my integration tests and seed the database with DropCreateDatabaseAlways, it generates the wrong column name for the PK.

Here is the DDL generated by the EF Power Tools in Visual Studio:

```
create table [dbo].[BusinessEntity] (
[BusinessEntityId] [bigint] not null identity,
...,
primary key ([BusinessEntityId])
);
```

and here is the SQL that was executed when seeding the database:
```
CREATE TABLE [dbo].[BusinessEntity] (
[TrustId] [bigint] NOT NULL IDENTITY,
...
```
BusinessEntity is my abstract base class and Trust is one of its subtypes (there are about ten in all):

```
public abstract class BusinessEntity
{
[Column("Id")]
public virtual Int64 Id { get; protected set; }
}

[Table("BusinessEntity")]
public class Trust : BusinessEntity
{
}
```

I have a naming convention that changes the Id property of my classes to <class>Id. Here it is:

```
/// <summary>
/// Overrides the EF ColumnAttributeConvention so that we can automatically map Id columns as tablenameId.
/// To get this to work, add the Column attribute to your class's Id property: [Column("Id"]. The db
/// column name will then become typeId, eg Id on Person becomes PersonId.
/// </summary>
public class OverrideColumnAttributeConvention : ColumnAttributeConvention
{
private const string IdColumn = "Id";

public override void Apply(ConventionPrimitivePropertyConfiguration configuration, ColumnAttribute attribute)
{
if (attribute.Name.HasValue() && attribute.Name.Equals(IdColumn, StringComparison.InvariantCultureIgnoreCase))
{
var type = configuration.ClrPropertyInfo.ReflectedType;
if (type != null)
{
var columnName = string.Format("{0}{1}", type.Name, attribute.Name);
configuration.HasColumnName(columnName);
configuration.HasColumnOrder(0);
}
}

base.Apply(configuration, attribute);
}
}

```

If I step through the integration test in the debugger, I can see my convention being called and returning the correct PK column name.

Note that this code has all been working fine in 6.1.1 but breaks with 6.1.2.

Edited Unassigned: Composite Varchar PK/Relationship Nulled by Update [2698]

$
0
0
I am working with EF 6.1.2 against a "legacy" DB. I have a table (Site) with a composite PK, which is two varchar fields (SiteId/OrgId). I have a relationship between this table and another table (WorkOrder) that has the same fields, which are used as the joining keys in the relationship. This relationship is defined in an EF Mapping:

WorkOrder
```
// Primary Key
this.HasKey(t => new { t.SITEID, t.ORGID });

// Relationship
this.HasRequired(t => t.SITE)
.WithMany(t =>t.FMXWORKORDERs)
.HasForeignKey(d => new { d.SITEID, d.ORGID })
.WillCascadeOnDelete(false);
```

Whenever I attempt to update the attached WorkOrder, if the Site Navigation property is null, even if the relationship keys are not null (SiteID and OrgID), EF nulls the SiteId field, which is required. If I load up the Site Navigation Property with lazy/eager loading first, all works fine.

Is there a problem with having a varchar composite PK and using that in a relationship? Why does the navigation property affect what EF does with the relationship fields?

Commented Unassigned: Seed database with DropCreateDatabaseAlways creates wrongly-named PK column with Table-Per-Hierarchy [2699]

$
0
0
I upgraded from EF 6.1.1 to 6.1.2 using NUGet. I had taken a copy of the DDL generated with 6.1.1 and compared it with 6.1.2 and they are identical. However, when I run my integration tests and seed the database with DropCreateDatabaseAlways, it generates the wrong column name for the PK.

Here is the DDL generated by the EF Power Tools in Visual Studio:

```
create table [dbo].[BusinessEntity] (
[BusinessEntityId] [bigint] not null identity,
...,
primary key ([BusinessEntityId])
);
```

and here is the SQL that was executed when seeding the database:
```
CREATE TABLE [dbo].[BusinessEntity] (
[TrustId] [bigint] NOT NULL IDENTITY,
...
```
BusinessEntity is my abstract base class and Trust is one of its subtypes (there are about ten in all):

```
public abstract class BusinessEntity
{
[Column("Id")]
public virtual Int64 Id { get; protected set; }
}

[Table("BusinessEntity")]
public class Trust : BusinessEntity
{
}
```

I have a naming convention that changes the Id property of my classes to <class>Id. Here it is:

```
/// <summary>
/// Overrides the EF ColumnAttributeConvention so that we can automatically map Id columns as tablenameId.
/// To get this to work, add the Column attribute to your class's Id property: [Column("Id"]. The db
/// column name will then become typeId, eg Id on Person becomes PersonId.
/// </summary>
public class OverrideColumnAttributeConvention : ColumnAttributeConvention
{
private const string IdColumn = "Id";

public override void Apply(ConventionPrimitivePropertyConfiguration configuration, ColumnAttribute attribute)
{
if (attribute.Name.HasValue() && attribute.Name.Equals(IdColumn, StringComparison.InvariantCultureIgnoreCase))
{
var type = configuration.ClrPropertyInfo.ReflectedType;
if (type != null)
{
var columnName = string.Format("{0}{1}", type.Name, attribute.Name);
configuration.HasColumnName(columnName);
configuration.HasColumnOrder(0);
}
}

base.Apply(configuration, attribute);
}
}

```

If I step through the integration test in the debugger, I can see my convention being called and returning the correct PK column name.

Note that this code has all been working fine in 6.1.1 but breaks with 6.1.2.
Comments: If it is of any help to you, if I rename the column in the database to BusinessEntityId and run a unit test that does not seed the database but just uses my DbContext, it also creates the wrong column name, ie different to the Power Tools DDL: exec sp_executesql N'SELECT [Limit1].[C2] AS [C1], [Limit1].[C1] AS [C2], [Limit1].[TrustId] AS [TrustId], It should be BusinessEntityId.

Edited Unassigned: Performance: Update translator does not cache command definition [2697]

$
0
0
Souce code indicates, that UpdateTranslator caches the comand definition. At the beginning it checks if if the Nodification function mapping is present in dictionary:

```
// Generates and caches a command definition for the given function
internal DbCommandDefinition GenerateCommandDefinition(ModificationFunctionMapping functionMapping)
{
if (null == _modificationFunctionCommandDefinitions)
{
_modificationFunctionCommandDefinitions = new Dictionary<ModificationFunctionMapping, DbCommandDefinition>();
}
DbCommandDefinition commandDefinition;
if (!_modificationFunctionCommandDefinitions.TryGetValue(functionMapping, out commandDefinition))
{
```

when the definition is not in dictionary, it creates new definition, but fails to put the result in dictionary.

The result is quite a big performance penallty. If the context contains 1000 new records, the command definitions is re-created for each insert. The definition is actually created by underlying DB provider. In my case this is Oracle ODP.NET, which is quite slow - based on profiler result, it takes 83% of CPU time of UpdateTranslator.ProduceCommands.

Suggested fix:
Add line: _modificationFunctionCommandDefinitions.Add(functionMapping, commandDefinition) three lines before fucntion ends.

Commented Unassigned: Performance: Update translator does not cache command definition [2697]

$
0
0
Souce code indicates, that UpdateTranslator caches the comand definition. At the beginning it checks if if the Nodification function mapping is present in dictionary:

```
// Generates and caches a command definition for the given function
internal DbCommandDefinition GenerateCommandDefinition(ModificationFunctionMapping functionMapping)
{
if (null == _modificationFunctionCommandDefinitions)
{
_modificationFunctionCommandDefinitions = new Dictionary<ModificationFunctionMapping, DbCommandDefinition>();
}
DbCommandDefinition commandDefinition;
if (!_modificationFunctionCommandDefinitions.TryGetValue(functionMapping, out commandDefinition))
{
```

when the definition is not in dictionary, it creates new definition, but fails to put the result in dictionary.

The result is quite a big performance penallty. If the context contains 1000 new records, the command definitions is re-created for each insert. The definition is actually created by underlying DB provider. In my case this is Oracle ODP.NET, which is quite slow - based on profiler result, it takes 83% of CPU time of UpdateTranslator.ProduceCommands.

Suggested fix:
Add line: _modificationFunctionCommandDefinitions.Add(functionMapping, commandDefinition) three lines before fucntion ends.

Comments: @divega - does this seem like a safe thing to do? If so, we think we should farm it out to someone to dig into.

Closed Unassigned: Code First: Allow subclasses to map field to same database column with TPH inheritance [2690]

$
0
0
I have the same problem found in this issue [here](https://entityframework.codeplex.com/workitem/583). I'm using <package id="EntityFramework" version="6.1.2" targetFramework="net45" />, testing it in Console Application and I guess the bug still linger.

Comments: Closing as requested info has not been provided

Edited Issue: Improve exception message for incorrect column type for configuration conventions [1628]

$
0
0

Calling
var modelBuilder = new DbModelBuilder();
modelBuilder.Entity<LightweightEntityWithAnnotations>();
modelBuilder.Properties()
.Configure(p => p.HasColumnType("foo"));
modelBuilder.Build(ProviderRegistry.Sql2008_ProviderInfo);

Results in this exception:

System.InvalidOperationException : Sequence contains no matching element
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
Utilities\DbProviderManifestExtensions.cs(16,0): at System.Data.Entity.Utilities.DbProviderManifestExtensions.GetStoreTypeFromName(DbProviderManifest providerManifest, String name)
ModelConfiguration\Configuration\Properties\Primitive\PrimitivePropertyConfiguration.cs(258,0): at System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.Configure(EdmProperty column, EntityType table, DbProviderManifest providerManifest, Boolean allowOverride, Boolean fillFromExistingConfiguration)
ModelConfiguration\Configuration\Properties\Primitive\PrimitivePropertyConfiguration.cs(169,0): at System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.<>c__DisplayClass1.<Configure>b__0(Tuple`2 pm)
c:\enlistments\OpenEF\src\Common\IEnumerableExtensions.cs(53,0): at System.Data.Entity.Utilities.IEnumerableExtensions.Each[T](IEnumerable`1 ts, Action`1 action)
ModelConfiguration\Configuration\Properties\Primitive\PrimitivePropertyConfiguration.cs(169,0): at System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.Configure(IEnumerable`1 propertyMappings, DbProviderManifest providerManifest, Boolean allowOverride, Boolean fillFromExistingConfiguration)
ModelConfiguration\Configuration\Types\StructuralTypeConfiguration.cs(176,0): at System.Data.Entity.ModelConfiguration.Configuration.Types.StructuralTypeConfiguration.ConfigurePropertyMappings(IList`1 propertyMappings, DbProviderManifest providerManifest, Boolean allowOverride)
ModelConfiguration\Configuration\Types\EntityTypeConfiguration.cs(660,0): at System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.ConfigurePropertyMappings(DbDatabaseMapping databaseMapping, EntityType entityType, DbProviderManifest providerManifest, Boolean allowOverride)
ModelConfiguration\Configuration\Types\EntityTypeConfiguration.cs(587,0): at System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.Configure(EntityType entityType, DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest)
ModelConfiguration\Configuration\ModelConfiguration.cs(533,0): at System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.ConfigureEntityTypes(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest)
ModelConfiguration\Configuration\ModelConfiguration.cs(377,0): at System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.Configure(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest)
DbModelBuilder.cs(409,0): at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
DbModelBuilder.cs(362,0): at System.Data.Entity.DbModelBuilder.Build(DbProviderInfo providerInfo)
Viewing all 10318 articles
Browse latest View live




Latest Images