Quantcast
Channel: Entity Framework

Reviewed: EF 6.1.3 (二月 20, 2017)

$
0
0
Rated 5 Stars (out of 5) - 好好好好好好好好好好好

Reviewed: EF 6.0.0 (二月 20, 2017)

$
0
0
Rated 3 Stars (out of 5) - 1111111111111111111111111

Reviewed: EF 6.1.3 (2月 24, 2017)

$
0
0
Rated 5 Stars (out of 5) - 好好好好好好好好好好好

Closed Unassigned: Support DateTimeOffset.DateTime and DateTime.Date properties. [2963]

$
0
0
I'm finding it next to impossible to get the local DateTime component of a DateTimeOffset in entity framework. It must use a "cast(x as datetime2(7))" as opposed to a convert, because any kind of conversion typically treats it as a UTC time. Alternatively, add DbFunctions.TruncateOffset. There is already a TruncateTime function, but that's useless, because it truncates the time and keeps the offset. I need a method that truncates the offset and keeps the time, so that I can query for the local part of the DateTimeOffset field.



var startDate = new DateTime(2016,12,15,8,0,0); //Dec 15, 2016 8:00AM

Assuming 'StartInstant' is a nullable DateTimeOffset field, I'd like to be able to do one of these:

If you added support for the DateTIme property of DateTimeOffset:
query.Where(x => x.StartInstant.Value.DateTime >= startDate);
//Generated SQL... "where cast(StartInstant as datetime2(7)) >= @p__linq__0"

If you added DbFunctions method "DateTime? TruncateOffset(DateTimeOffset?)":
query.Where(x => DbFunctions.TruncateOffset(x.StartInstant) >= startDate);
//Generated SQL... "where cast(StartInstant as datetime2(7)) >= @p__linq__0"

Currently my only option is this monster, which also loses some precision and generates what surely is nasty index-busting SQL for the field:
query.Where(x => DbFunctions.CreateDateTime(x.StartInstant.Value.Year, x.StartInstant.Value.Month, x.StartInstant.Value.Day, x.StartInstant.Value.Hour, x.StartInstant.Value.Minute, x.StartInstant.Value.Second) >= startDate);
//Generated SQL (yes, seriously>>>)... ((convert (datetime2,right(''000'' + convert(varchar(255), DATEPART (year, [Extent1].[StartInstant])), 4) + ''-'' + convert(varchar(255), DATEPART (month, [Extent1].[StartInstant])) + ''-'' + convert(varchar(255), DATEPART (day, [Extent1].[StartInstant])) + '' '' + convert(varchar(255), DATEPART (hour, [Extent1].[StartInstant])) + '':'' + convert(varchar(255), DATEPART (minute, [Extent1].[StartInstant])) + '':'' + str( CAST( DATEPART (second, [Extent1].[StartInstant]) AS float), 10, 7), 121)) >= @p__linq__0
Comments: **EF Team Triage:** Thanks for reporting an issue on Entity Framework 6.x. This project is now maintained on GitHub (https://github.com/aspnet/EntityFramework6). Please file your issue on the GitHub issue tracker. **We will no longer be monitoring this issue tracker for comments, so please do not reply here.**

Closed Unassigned: Migrate from Xml.Linq.XDocument to VersionedModel.VersionedModel [2964]

$
0
0
Based on previous commits from this repository, we identify that we are migrating the version that uses the type Xml.Linq.XDocument to the type VersionedModel.VersionedModel. For instance, in commit 14623da, you performed 19 edits of this kind: 18 on class HistoryRepositoryTests.cs and 1 on class InternalContext.cs. But other locations in the source code still need to be migrated. Is not it the case to migrate the additional locations?
Link to the commit: [https://entityframework.codeplex.com/SourceControl/changeset/14623da1e612d16c52b331bbd37ac1294c856658](https://entityframework.codeplex.com/SourceControl/changeset/14623da1e612d16c52b331bbd37ac1294c856658)

Comments: **EF Team Triage:** Thanks for reporting an issue on Entity Framework 6.x. This project is now maintained on GitHub (https://github.com/aspnet/EntityFramework6). Please file your issue on the GitHub issue tracker. **We will no longer be monitoring this issue tracker for comments, so please do not reply here.**

Reviewed: EF 6.0.0 (三月 15, 2017)

$
0
0
Rated 4 Stars (out of 5) - safe,want more freedom for ways .

Created Unassigned: Exception in System.Data.Entity.Core.Common.DbProviderServices.ExpandDataDirectory(String path) [2965]

$
0
0
i have a clickonce deployed WPF application where we have marked our SQL Local database as a data component. At times when the clickonce is upgraded our database is kind of inaccessible from the application and all DB operations fail.

Following log is seen in the log file:
Database Initialization Failed : __Expansion of |DataDirectory| failed while processing the connection string. Ensure that |DataDirectory| is set to a valid fully-qualified path__.
System.ArgumentException: Expansion of |DataDirectory| failed while processing the connection string. Ensure that |DataDirectory| is set to a valid fully-qualified path.
__at System.Data.Entity.Core.Common.DbProviderServices.ExpandDataDirectory(String path)__
at System.Data.Entity.SqlServer.SqlProviderServices.GetOrGenerateDatabaseNameAndGetFileNames(SqlConnection sqlConnection, String& databaseName, String& dataFileName, String& logFileName)
at System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
at System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
at System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase()
at System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection)
at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)

When i went to the code piece(in bold above) I can see a if block like this:
// Verify root folder path is a real path without unexpected "..\"
if (rootFolderPath.Contains(".."))
{
throw new ArgumentException(Strings.ExpandingDataDirectoryFailed);
}


When we watched the location of the data folder, it was something like this:
__C:\Users\<USERNAME>\AppData\Local\Apps\2.0\Data\98O56D2Q.EM1\R4LXLEL4.85M\tech..tion_0000000000000000_0003.0001_80c92a08f8b673c0\Data__


So it results that our path did contain __(..)__. But based on the if block check this actually does not satisfies the condition because it is not at the start of the folder location.
As per my suggestion the if block should be like:
// Verify root folder path is a real path without unexpected "..\"
if (rootFolderPath.StartsWith("..\", StringComparison.Ordinal))
{
throw new ArgumentException(Strings.ExpandingDataDirectoryFailed);
}


Please suggest what should I do as the install folder path is not under control. The name and path is decided by the clickonce deployment strategy. Waiting for your reply.

Edited Unassigned: Exception in System.Data.Entity.Core.Common.DbProviderServices.ExpandDataDirectory(String path) [2965]

$
0
0
i have a clickonce deployed WPF application where we have marked our SQL Local database as a data component. At times when the clickonce is upgraded our database is kind of inaccessible from the application and all DB operations fail.

Following log is seen in the log file:
Database Initialization Failed : __Expansion of |DataDirectory| failed while processing the connection string. Ensure that |DataDirectory| is set to a valid fully-qualified path__.
System.ArgumentException: Expansion of |DataDirectory| failed while processing the connection string. Ensure that |DataDirectory| is set to a valid fully-qualified path.
__at System.Data.Entity.Core.Common.DbProviderServices.ExpandDataDirectory(String path)__
at System.Data.Entity.SqlServer.SqlProviderServices.GetOrGenerateDatabaseNameAndGetFileNames(SqlConnection sqlConnection, String& databaseName, String& dataFileName, String& logFileName)
at System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
at System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
at System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase()
at System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection)
at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)

When i went to the code piece(in bold above) I can see a if block like this:
// Verify root folder path is a real path without unexpected "..\"
if (rootFolderPath.Contains(".."))
{
throw new ArgumentException(Strings.ExpandingDataDirectoryFailed);
}


When we watched the location of the data folder, it was something like this:
__C:\Users\<USERNAME>\AppData\Local\Apps\2.0\Data\98O56D2Q.EM1\R4LXLEL4.85M\tech..tion_0000000000000000_0003.0001_80c92a08f8b673c0\Data__


So it results that our path at __"tech..tion_0000000000000000_0003.0001_80c92a08f8b673c0"__ do contains __(..)__.

But based on the if block check this actually does not satisfies the condition because it is not at the start of the folder location.

As per my suggestion the if block should be like:
// Verify root folder path is a real path without unexpected "..\"
if (rootFolderPath.StartsWith("..\", StringComparison.Ordinal))
{
throw new ArgumentException(Strings.ExpandingDataDirectoryFailed);
}


Please suggest what should I do as the install folder path is not under control. The name and path is decided by the clickonce deployment strategy. Waiting for your reply.

Commented Unassigned: Exception in System.Data.Entity.Core.Common.DbProviderServices.ExpandDataDirectory(String path) [2965]

$
0
0
i have a clickonce deployed WPF application where we have marked our SQL Local database as a data component. At times when the clickonce is upgraded our database is kind of inaccessible from the application and all DB operations fail.

Following log is seen in the log file:
Database Initialization Failed : __Expansion of |DataDirectory| failed while processing the connection string. Ensure that |DataDirectory| is set to a valid fully-qualified path__.
System.ArgumentException: Expansion of |DataDirectory| failed while processing the connection string. Ensure that |DataDirectory| is set to a valid fully-qualified path.
__at System.Data.Entity.Core.Common.DbProviderServices.ExpandDataDirectory(String path)__
at System.Data.Entity.SqlServer.SqlProviderServices.GetOrGenerateDatabaseNameAndGetFileNames(SqlConnection sqlConnection, String& databaseName, String& dataFileName, String& logFileName)
at System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
at System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
at System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase()
at System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection)
at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)

When i went to the code piece(in bold above) I can see a if block like this:
// Verify root folder path is a real path without unexpected "..\"
if (rootFolderPath.Contains(".."))
{
throw new ArgumentException(Strings.ExpandingDataDirectoryFailed);
}


When we watched the location of the data folder, it was something like this:
__C:\Users\<USERNAME>\AppData\Local\Apps\2.0\Data\98O56D2Q.EM1\R4LXLEL4.85M\tech..tion_0000000000000000_0003.0001_80c92a08f8b673c0\Data__


So it results that our path at __"tech..tion_0000000000000000_0003.0001_80c92a08f8b673c0"__ do contains __(..)__.

But based on the if block check this actually does not satisfies the condition because it is not at the start of the folder location.

As per my suggestion the if block should be like:
// Verify root folder path is a real path without unexpected "..\"
if (rootFolderPath.StartsWith("..\", StringComparison.Ordinal))
{
throw new ArgumentException(Strings.ExpandingDataDirectoryFailed);
}


Please suggest what should I do as the install folder path is not under control. The name and path is decided by the clickonce deployment strategy. Waiting for your reply.
Comments: Avoid using DataDirectory in your connection string, resolve the path yourself

Closed Unassigned: Exception in System.Data.Entity.Core.Common.DbProviderServices.ExpandDataDirectory(String path) [2965]

$
0
0
i have a clickonce deployed WPF application where we have marked our SQL Local database as a data component. At times when the clickonce is upgraded our database is kind of inaccessible from the application and all DB operations fail.

Following log is seen in the log file:
Database Initialization Failed : __Expansion of |DataDirectory| failed while processing the connection string. Ensure that |DataDirectory| is set to a valid fully-qualified path__.
System.ArgumentException: Expansion of |DataDirectory| failed while processing the connection string. Ensure that |DataDirectory| is set to a valid fully-qualified path.
__at System.Data.Entity.Core.Common.DbProviderServices.ExpandDataDirectory(String path)__
at System.Data.Entity.SqlServer.SqlProviderServices.GetOrGenerateDatabaseNameAndGetFileNames(SqlConnection sqlConnection, String& databaseName, String& dataFileName, String& logFileName)
at System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
at System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
at System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase()
at System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection)
at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)

When i went to the code piece(in bold above) I can see a if block like this:
// Verify root folder path is a real path without unexpected "..\"
if (rootFolderPath.Contains(".."))
{
throw new ArgumentException(Strings.ExpandingDataDirectoryFailed);
}


When we watched the location of the data folder, it was something like this:
__C:\Users\<USERNAME>\AppData\Local\Apps\2.0\Data\98O56D2Q.EM1\R4LXLEL4.85M\tech..tion_0000000000000000_0003.0001_80c92a08f8b673c0\Data__


So it results that our path at __"tech..tion_0000000000000000_0003.0001_80c92a08f8b673c0"__ do contains __(..)__.

But based on the if block check this actually does not satisfies the condition because it is not at the start of the folder location.

As per my suggestion the if block should be like:
// Verify root folder path is a real path without unexpected "..\"
if (rootFolderPath.StartsWith("..\", StringComparison.Ordinal))
{
throw new ArgumentException(Strings.ExpandingDataDirectoryFailed);
}


Please suggest what should I do as the install folder path is not under control. The name and path is decided by the clickonce deployment strategy. Waiting for your reply.
Comments: **EF Team Triage:** Thanks for reporting an issue on Entity Framework 6.x. This project is now maintained on GitHub (https://github.com/aspnet/EntityFramework6). Please file your issue on the GitHub issue tracker. **We will no longer be monitoring this issue tracker for comments, so please do not reply here.**

Created Unassigned: During DbDatabaseExist call, the AssociationSet do not have correct details; if Fluent APIs or Data Annotations are used to modify the Table Name participating in the ForeignKey relationship. The AssociationSet still preserves the old name defined in the [2966]

$
0
0
We are third party EF provider and we are seeing an issue with CreateIfNotExist. With this call our provider generates a query to look for database objects like tables, keys e.t.c for the Context.
And if in model table name is modified using dataannotations or fluent api we see an issue in foreign key names.

Foreign Key name is dependent on table name and foreign key columns. In DbDatabaseExists method we generate a query to identify existence of database objects for the context. And inside the same method for ForeignKey names we refer AssociationSet of StoreItemCollection that we receive in DbDatabaseExists. But the problem is we are not receiving AssociationSet with correct details, it shows the table name same as class name instead of name which was specified in data annotation or fluent api. This results in wrong Foreign Key name to be searched. But create database object queries are getting generated correctly.

And as there is difference in foreign key names that were used while creating and verifying, provider gets mislead that database is not present in backend. And thus, tries to create database objects. And fails with Table or View already exists.

So, our issue will get resolved if AssociationSet is correctly updated with data annotation or fluent api table names.

Closed Unassigned: During DbDatabaseExist call, the AssociationSet do not have correct details; if Fluent APIs or Data Annotations are used to modify the Table Name participating in the ForeignKey relationship. The AssociationSet still preserves the old name defined in the [2966]

$
0
0
We are third party EF provider and we are seeing an issue with CreateIfNotExist. With this call our provider generates a query to look for database objects like tables, keys e.t.c for the Context.
And if in model table name is modified using dataannotations or fluent api we see an issue in foreign key names.

Foreign Key name is dependent on table name and foreign key columns. In DbDatabaseExists method we generate a query to identify existence of database objects for the context. And inside the same method for ForeignKey names we refer AssociationSet of StoreItemCollection that we receive in DbDatabaseExists. But the problem is we are not receiving AssociationSet with correct details, it shows the table name same as class name instead of name which was specified in data annotation or fluent api. This results in wrong Foreign Key name to be searched. But create database object queries are getting generated correctly.

And as there is difference in foreign key names that were used while creating and verifying, provider gets mislead that database is not present in backend. And thus, tries to create database objects. And fails with Table or View already exists.

So, our issue will get resolved if AssociationSet is correctly updated with data annotation or fluent api table names.

Comments: **EF Team Triage:** Thanks for reporting an issue on Entity Framework 6.x. This project is now maintained on GitHub (https://github.com/aspnet/EntityFramework6). Please file your issue on the GitHub issue tracker. **We will no longer be monitoring this issue tracker for comments, so please do not reply here.**

Created Unassigned: Working with transactions [2967]

$
0
0
Hi,

We have a main entity called "VOB" that it's related to 10 more, we have created a webapi controller to persist the VOB changes in the database, those changes implies changes in the other 10 entities too. To accomplish that we used transactions, one transaction that takes care of 10 possible commit to the database. To make post method shorter we decided to split it in different blocks of code, using different classes, see the pictures attached. As you can see, to keep the transaction we passed the dbContext as a parameter is this a correnct way to accomplish it ?

Thanks.


Reviewed: EF 5.0.0 (六月 09, 2017)

$
0
0
Rated 5 Stars (out of 5) - 下载来看看能用么......希望能用到

Commented Issue: If an entity MyEntity has a property called MyProp, I cannot create an entity called MyEntity_MyProp [2727]

$
0
0
Copied from github: https://github.com/aspnet/EntityFramework/issues/1979

I'm using Entity Framework 6, with POCO and fluent-API and I've noticed an annoying bug.

If I have an entity called MyEntity and this entity has a property called MyProp, that makes it impossible to create an entity called MyEntity_MyProp.

```
The item with identity 'MyEntity_MyProp' already exists in the metadata collection.\r\nParameter name: item
```

The error immediately goes away if I rename any of the entities, or rename the properties.

The "bug" is obvious: the key [EntityName]_[PropertyName] must be unique in the metadata collection.

Screenshot: (attached)

I'm migrating a huge Entity Framework model with 390+ classes from EF 4, database first, to EF 6, code first, with fluent-API. It's out of question to rename the entities or the tables.

How do I solve that?


Comments: For reference, I created the issue here: https://github.com/aspnet/EntityFramework6/issues/308

Closed Unassigned: Working with transactions [2967]

$
0
0
Hi,

We have a main entity called "VOB" that it's related to 10 more, we have created a webapi controller to persist the VOB changes in the database, those changes implies changes in the other 10 entities too. To accomplish that we used transactions, one transaction that takes care of 10 possible commit to the database. To make post method shorter we decided to split it in different blocks of code, using different classes, see the pictures attached. As you can see, to keep the transaction we passed the dbContext as a parameter is this a correnct way to accomplish it ?

Thanks.


Comments: **EF Team Triage:** Thanks for reporting an issue on Entity Framework 6.x. This project is now maintained on GitHub (https://github.com/aspnet/EntityFramework6). Please file your issue on the GitHub issue tracker. **We will no longer be monitoring this issue tracker for comments, so please do not reply here.**

Reviewed: EF 6.1.3 (Jul 16, 2017)

$
0
0
Rated 4 Stars (out of 5) - qqqqqqqqqqqqqqqqqqqqqqqqq

Reviewed: EF 6.0.0 (八月 08, 2017)

$
0
0
Rated 4 Stars (out of 5) - very good~~~

Reviewed: EF 6.1.3 (八月 24, 2017)

$
0
0
Rated 5 Stars (out of 5) - nice,very good

Reviewed: EF 6.1.3 (10 26, 2017)

$
0
0
Rated 5 Stars (out of 5) - ahahahahahahahahahahaa




Latest Images