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

Edited Issue: Projections with .ToString() fails when UseDatabaseNullSemantics = true [2519]

$
0
0
In EF 6.1.2 beta:
ToString() fails for all datatypes when dbContext.Configuration.UseDatabaseNullSemantics = true
(with message "The specified cast from a materialized 'System.xxx' type to the 'System.String' type is not valid")

The generated sql with UseDatabaseNullSemantics = true:
SELECT [Extent1].[Id] AS [Id] FROM [dbo].[Entities] AS [Extent1]

The generated sql with UseDatabaseNullSemantics = false
SELECT [Extent1].[Id] AS [Id], CAST( [Extent1].[Id] AS nvarchar(max))AS [C1]FROM [dbo].[Entities] AS [Extent1]

```
public class Entity
{
public int Id { get; set; }
public string Name { get; set; }
}

public class Db : DbContext
{
public DbSet<Entity> Entities { get; set; }
}

static void Main(string[] args)
{
var db = new Db();
db.Configuration.UseDatabaseNullSemantics = true;
db.Entities.Add(new Entity { Name = "Test" + DateTime.Now });
db.SaveChanges();

var list = db.Entities.Select(d => new { Id = d.Id.ToString() }).ToList();
//fails with The specified cast from a materialized 'System.Int32' type to the 'System.String' type is not valid.
}
```


Edited Unassigned: entoty framework 6.1.1 code first startup very slowly [2518]

$
0
0
hello, I'm struggling with the performance of entity framework 6.1.1, in the initial phase lose too much time.
The application and consists of about 200 tables and some are related.
Using EntityFramework code first.
in the real application loses about 15 seconds and for the end user too.

I created an example and loses about 8 seconds (because there is no interface) because I think they are too many does nothing ke nizializzare less than 100 entities in this example.

how you can improve?

this is the example [here](https://drive.google.com/file/d/0B0IzbkNqehmacHJnNE16TlBuWDA/edit?usp=sharing)

Edited Unassigned: Use a custom type as store procedure Complex return type [2517]

$
0
0
I want to be able to select an existing poco class which is in a different project as a return type for a store procedure.

Commented Unassigned: Use a custom type as store procedure Complex return type [2517]

$
0
0
I want to be able to select an existing poco class which is in a different project as a return type for a store procedure.
Comments: Hey Lawrence, We think you might be able to do this already, can you check?

Edited Unassigned: Inheritance change state exception [2514]

$
0
0
I am using Inheritance with EF
The parent class is Identity and it has two driven classes User ans Role
when I save a user everything work fine, when I save role I get an error at this code
DataContext.Entry(record).State = EntityState.Added;

The error message is:
Unable to set field/property Identity on entity type Role. See InnerException for details.
InnerException : "Unable to cast object of type 'Role' to type 'User'.

Thank you

Edited Issue: EDM fails to recognise our 64 bit EF provider for EF 6 [2506]

$
0
0
we are developing an EF provider to support one of our databases. We have 32 bit EF provider which uses 32 bit db provider and it works fine. But we have some issues with our 64 bit EF provider which depends on 64 bit dbprovider. If we manually add reference to our EF provider in the application and keep the application process architecture as 64 bit, it works fine. But moment we use EDM to use Database First approach, EDM wizard fails with a message implying it was not able to find the compatible dbprovider. From our debugging, it appears the EDM is trying to create a AppDomain(as a 32 bit) and try to load the project exe(which is 64 bit) and in that process it fails complaining about a mismatch in process architecture. The Fusion Log is not showing any reference to our providers(EF or DB).

Any known issues or any clue as to what may be wrong here?

Any help or suggestion much appreciated.

Commented Unassigned: EF creates unnecessary Filter subquery hence Sql server FTS predicates fail [2525]

$
0
0
Here is corresponding bug in Sql server connect: http://connect.microsoft.com/SQLServer/feedbackdetail/view/982192/sql-server-does-not-recognize-fulltexted-column-in-subquery

So basically, I rewrite a query using FTSInterceptor http://www.entityframework.info/Home/FullTextSearch
it worked ok, but now fails since EF started to move out my where conditions from the Extent query into Filter query. Therefore now my query fails and I cannot figure why EF does this. I'll attach 2 similar queries , they are different only by 1 where clause but one works and the second fails.

Comments: Is there any workaround for this behavior?

New Post: How to define a computed column (without SQL)?

$
0
0
Hi,

is it possible to define a computed column without manually modifying migration file?

I'd expect something like this
        [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
        public string FullName
        {
            get { return FirstName + " " + LastName; }
            private set { }
        }
to produce a fully functional computed column, but it doesn't work (value is always null).

Is it possible to do this without adding a custom SQL code to migration file? If it's not possible, is it a planned feature?

Commented Issue: UpForGrabs: Index renaming not supported in SQLCE [2442]

$
0
0
The ```RenameIndex()``` method returns this error when migrating with SQLCE:

_"Direct index renaming is not supported by SQL Server Compact. To rename an index in SQL Server Compact, you will need to recreate it."_

Instead, ```DropIndex()``` and then ```CreateIndex()``` should be called. It's possible to manually edit the migration accordingly, prior to updating, but this is tedious and error-prone.

Comments: > SqlCeMigration provider I'm not finding the documentation for this... do you have a link?

Commented Issue: UpForGrabs: Index renaming not supported in SQLCE [2442]

$
0
0
The ```RenameIndex()``` method returns this error when migrating with SQLCE:

_"Direct index renaming is not supported by SQL Server Compact. To rename an index in SQL Server Compact, you will need to recreate it."_

Instead, ```DropIndex()``` and then ```CreateIndex()``` should be called. It's possible to manually edit the migration accordingly, prior to updating, but this is tedious and error-prone.

Comments: @InteXX Sure: https://entityframework.codeplex.com/SourceControl/latest#src/EntityFramework.SqlServerCompact/SqlCeMigrationSqlGenerator.cs

Created Unassigned: Incorrect Evaluation of Nullable Strings [2528]

$
0
0
I have come across a difference in EF over L2S and SQL Server while migrating code and am not sure whether this is a bug or a breaking change.

If I have an SQL Table:

```
CREATE TABLE Test
(
ID Int NOT NULL IDENTITY (1,1),
SomeString varchar(50),
CONSTRAINT PK_IDField PRIMARY KEY (ID)
)
```

I add some data

```
INSERT INTO Test (SomeString) Values ('Text1')
INSERT INTO Test (SomeString) Values ('Text2')
INSERT INTO Test (SomeString) Values (Null)
```

The difference occurs as follows:

SQL
```
SELECT * FROM Test WHERE SomeString <> '' 'Returns __2__ records
```

L2S
```
context.Tests.Where(Function(t) t.SomeString <> "") 'Returns __2__ records
```

EF6.1.1
```
entities.Tests.Where(Function(t) t.SomeString <> "") 'Returns __3__ records
```

Whilst I know I can use .Length > 0, this has broken my previous code and have to go through looking for <> "". I would consider this a breaking change, but thought I would raise this with you guys for clarity.

Commented Feature: "SELECT" Stored Procedures in EF (not only for I/U/D) [1772]

$
0
0
...what I mean with SELECT Stored Procedures was to select a SP and the Designer should build the Entity from the result of that SP - all of our Data access goes through Stored Procedures for Select/Insert/Update/Delete and the SELECT result doesn't often map to tables because we return special columns from multiple tables...
Comments: Hello, some News about this functionality? it would be very usefull for our next Project to migrate a big VB6 CRM to ASP MVC... Robert

Created Unassigned: CodeFirst DBcontext.SaveChanges return value higher than expected [2529]

$
0
0
EF 6.1.1 code first.

I create 41 new entities in my DBContext and nothing else. ChangeTracker.Entries() shows 41 added entities and nothing else. Sql Profiler shows 41 insert statements and nothing else. But SaveChanges returns 81.

I also see this when I create just two new entities on a collection - SaveChanges reports 4.

Details on Stack Overflow: (http://stackoverflow.com/questions/26118562/why-is-my-entity-framework-6-1-code-first-savechanges-count-higher-than-expect)

Note that I have tested this by removing all CommandTree interceptors and anything else that my code might be doing. This is doing a pure DbContext.SaveChanges.

Why would the count be different to the ChangeTrackerEntries count and the actual Sql statement count?

Commented Unassigned: Use a custom type as store procedure Complex return type [2517]

$
0
0
I want to be able to select an existing poco class which is in a different project as a return type for a store procedure.
Comments: __Note for triage:__ I took a chance to look at this while investigating other issues. While it is possible to have the ExternalTypeName annotation on most elements in the model and our default code generation template will honor it, the EF Designer only has UI for it in the Enum design dialog. The workaround is to place this annotation manually using an XML editor, e.g.: ``` <ComplexType Name="Address" a:ExternalTypeName="Bar.Address" xmlns:a="http://schemas.microsoft.com/ado/2006/04/codegeneration" > <Property Type="String" Name="Street" Nullable="false" /> </ComplexType> ``` I think it should be possible to write an extension for the designer to do this as well, but I haven't tried.

Edited Feature: Use a custom type as store procedure Complex return type [2517]

$
0
0
I want to be able to select an existing poco class which is in a different project as a return type for a store procedure.

Commented Issue: Projections with .ToString() fails when UseDatabaseNullSemantics = true [2519]

$
0
0
In EF 6.1.2 beta:
ToString() fails for all datatypes when dbContext.Configuration.UseDatabaseNullSemantics = true
(with message "The specified cast from a materialized 'System.xxx' type to the 'System.String' type is not valid")

The generated sql with UseDatabaseNullSemantics = true:
SELECT [Extent1].[Id] AS [Id] FROM [dbo].[Entities] AS [Extent1]

The generated sql with UseDatabaseNullSemantics = false
SELECT [Extent1].[Id] AS [Id], CAST( [Extent1].[Id] AS nvarchar(max))AS [C1]FROM [dbo].[Entities] AS [Extent1]

```
public class Entity
{
public int Id { get; set; }
public string Name { get; set; }
}

public class Db : DbContext
{
public DbSet<Entity> Entities { get; set; }
}

static void Main(string[] args)
{
var db = new Db();
db.Configuration.UseDatabaseNullSemantics = true;
db.Entities.Add(new Entity { Name = "Test" + DateTime.Now });
db.SaveChanges();

var list = db.Entities.Select(d => new { Id = d.Id.ToString() }).ToList();
//fails with The specified cast from a materialized 'System.Int32' type to the 'System.String' type is not valid.
}
```

Comments: Fixed by commit d91a484c79c3bae525e2b979545c9139ea9b72fe and available in the current nightly build.

Edited Issue: Projections with .ToString() fails when UseDatabaseNullSemantics = true [2519]

$
0
0
In EF 6.1.2 beta:
ToString() fails for all datatypes when dbContext.Configuration.UseDatabaseNullSemantics = true
(with message "The specified cast from a materialized 'System.xxx' type to the 'System.String' type is not valid")

The generated sql with UseDatabaseNullSemantics = true:
SELECT [Extent1].[Id] AS [Id] FROM [dbo].[Entities] AS [Extent1]

The generated sql with UseDatabaseNullSemantics = false
SELECT [Extent1].[Id] AS [Id], CAST( [Extent1].[Id] AS nvarchar(max))AS [C1]FROM [dbo].[Entities] AS [Extent1]

```
public class Entity
{
public int Id { get; set; }
public string Name { get; set; }
}

public class Db : DbContext
{
public DbSet<Entity> Entities { get; set; }
}

static void Main(string[] args)
{
var db = new Db();
db.Configuration.UseDatabaseNullSemantics = true;
db.Entities.Add(new Entity { Name = "Test" + DateTime.Now });
db.SaveChanges();

var list = db.Entities.Select(d => new { Id = d.Id.ToString() }).ToList();
//fails with The specified cast from a materialized 'System.Int32' type to the 'System.String' type is not valid.
}
```

Commented Issue: .Take(0) on queries against sql server 2012/14 works in EF611 but fails in EF612beta [2513]

$
0
0
```
var things = db.Things.OrderBy(t => t.Name).Skip(0).Take(0).ToList();
```
fails with "The number of rows provided for a FETCH clause must be greater then zero."

Applications should not generate queries with Take(0), but EF must survive them since it has worked before.

Comments: As far as I can see EF also supports "Take(Func<int>)", for example "Take(() => variable), in which case the generated SQL query will be parameterized. In that case EF cannot guess whether the value of the variable (parameter) will ever be 0. Here are a couple the options I can think of: 1. Fallback to v6.1.1 SQL if the value passed to Take is 0, in case of non-parameterized queries only. 2. Provide a configuration flag that will determine whether to generate v6.1.1 (ROW_NUMBER) or v6.1.2 (FETCH) SQL. The default will be v6.1.2, so the value needs to be explicitly set for v6.1.1. Before pursuing a potential solution, it is important to understand why exactly Take(0) is useful. We understand that we have a breaking change here, but it may not be worth trying to be backward compatible if Take(0) does not provide any value. Could you detail on why Take(0) is important in your case?

Commented Feature: Consider adding logic to detect setting unloaded nav prop to nulll in Lazy Loading proxies. [2074]

$
0
0
If you have two entities:

public class Foo { int? Id { get; set; } public virtual Bar Bar { get; set; }

and

public class Bar { int? Id { get; set; } }

Then if "Foo" has an assigned "Bar" when it is loaded from the DBContext, setting "Foo.Bar = null" has no effect, unless you first call the getter, e.g. "var ignored = foo.Bar; foo.Bar = null"

See also: http://stackoverflow.com/questions/21692401/entity-framework-will-only-set-related-entity-property-to-null-if-i-first-get
Comments: I think that this issue is also related to the problem described here: http://stackoverflow.com/questions/7496076/entity-framework-4-1-code-first-required-lazy-load-reference-is-null-on-save/ I have a virtual property which is a reference to another entity and it is marked as Required. When I load my entity and try to save it, without touching the property reference, I get a validation exception because it thinks the property is null. This is basically the same logical solecism: a property that has not been loaded but does have an underlying value is assumed to have no value.

Commented Feature: Consider adding logic to detect setting unloaded nav prop to nulll in Lazy Loading proxies. [2074]

$
0
0
If you have two entities:

public class Foo { int? Id { get; set; } public virtual Bar Bar { get; set; }

and

public class Bar { int? Id { get; set; } }

Then if "Foo" has an assigned "Bar" when it is loaded from the DBContext, setting "Foo.Bar = null" has no effect, unless you first call the getter, e.g. "var ignored = foo.Bar; foo.Bar = null"

See also: http://stackoverflow.com/questions/21692401/entity-framework-will-only-set-related-entity-property-to-null-if-i-first-get
Comments: Actually, this is a better discussion of the required+lazy problem, with various workarounds: http://stackoverflow.com/questions/6038541/ef-validation-failing-on-update-when-using-lazy-loaded-required-properties?lq=1
Viewing all 10318 articles
Browse latest View live


Latest Images

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