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

Commented Issue: Exception combining two DbCollectionEntry.Query() calls [1851]

$
0
0
I get

Unhandled Exception: System.ArgumentException: A parameter named 'EntityKeyValue1' already exists in the parameter collection. Parameter names must be unique in the parameter collection.
Parameter name: item
at System.Data.Entity.Core.Objects.ObjectParameterCollection.Add(ObjectParameter item)
at System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClassb.<GetResults>b__a()
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClassb.<GetResults>b__9()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Lazy`1.get_Value()
at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()

when combining two queries built from db.Entry(e).Collection(e => e.e2s).Query()

This happens both in EF5 and EF6.

Here's a complete repro:

class Author
{
public int ID { get; set; }
}
class Post
{
public int ID { get; set; }
public ICollection<Author> Authors { get; set; }
public ICollection<Comment> Comments { get; set; }
}
class Comment
{
public int ID { get; set; }
public Post Post { get; set; }
public ICollection<Author> Authors { get; set; }
}
class Context : DbContext
{
public DbSet<Post> Posts { get; set; }

static void Main()
{
using (Context db1 = new Context())
{
if (!db1.Posts.Any(p => p.ID == 1))
{
db1.Posts.Add(new Post { ID = 1, });
db1.SaveChanges();
}
}
using (Context db = new Context())
{
Post post = db.Posts.Find(1);
List<Author> authors = db.Entry(post).Collection(p => p.Authors).Query()
.Concat(db.Entry(post).Collection(p => p.Comments).Query().SelectMany(c => c.Authors))
.ToList();
}
}
}
Comments: I have a temporary workaround for this that seems to work. I had a look at the EF code and the issue is the AliasGenerator isn't aware of any existing usages when combining the queries. I am not sure the best place to either keep track of the EntityKeyValue's. As a workaround I grabbed the original ObjectQuery and did a string replace to avoid the conflicts. public static ObjectQuery<T> QueryDuplicateKeyFix<T>(ObjectQuery<T> brokenQuery, string suffix = "B") { var query = new ObjectQuery<T>(brokenQuery.CommandText.Replace("EntityKeyValue", "EntityKeyValueB"), brokenQuery.Context); foreach (var p in brokenQuery.Parameters) { var p1 = p; if (p.Name.StartsWith("EntityKeyValue" + suffix)) { p1 = new ObjectParameter(p.Name.Replace("EntityKeyValue", "EntityKeyValue" + suffix), p.Value); } query.Parameters.Add(p1); } return query; }

Commented Issue: Entity Framework Duplicate type name within an assembly (6.1.0) [2231]

$
0
0
I am not sure what is going on but I keep getting the following exception when doing a query. "Duplicate type name within an assembly." I had resolved the issue by removing entity framework from all the projects in the solutions and re-installing using nugget. Then all of the sudden the exception is back. I have verified my table schema over and over and find nothing wrong with. The issue keeps coming back and I have to keep repeating the steps mentioned above to resolve.

This is the query causing the exception.

```
var BaseQuery = from Users in db.Users
join UserInstalls in db.UserTenantInstalls on Users.ID equals UserInstalls.UserID
join Installs in db.TenantInstalls on UserInstalls.TenantInstallID equals Installs.ID
where
Users.Username == Username
&& Users.Password == Password
&& Installs.Name == Install
select Users;

var Query = BaseQuery.Include("UserTenantInstalls.TenantInstall");

return Query.FirstOrDefault();

```

Comments: Hi Luke, The error happens from time to time. For example, everything works for a little while then it starts blowing up. I can temporarily resolve it with the steps mentioned. Below is the stack trace from the last crash. Error: Duplicate type name within an assembly. Stack Trace: at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at System.Data.Entity.Core.Common.Internal.Materialization.Translator.TranslateColumnMap(Translator translator, Type elementType, ColumnMap columnMap, MetadataWorkspace workspace, SpanIndex spanIndex, MergeOption mergeOption, Boolean streaming, Boolean valueLayer) at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlanFactory.Prepare(ObjectContext context, DbQueryCommandTree tree, Type elementType, MergeOption mergeOption, Boolean streaming, Span span, IEnumerable`1 compiledQueryParameters, AliasGenerator aliasGenerator) at System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption) at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__6() at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__5() at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation) at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0() at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source) at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__1[TResult](IEnumerable`1 sequence) at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot) at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[TResult](Expression expression) at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression) at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source) at RM.Core.Service.Data.UserData.GetByInstall(String Username, String Password, String Install) in c:\TFS\Myapp\Myapp\Solutions\Myapp\RM.Core.Service\Data\User.cs:line 44 at RM.Core.Service.UserService.GetUserContext(String Username, String Password, String Install) in c:\TFS\Myapp\Myapp\Solutions\Myapp\RM.Core.Service\Service\UserService.cs:line 37 at RM.Application.ServiceManager.Authenticate(String Username, String Password, String Install) in c:\TFS\Myapp\Myapp\Solutions\Myapp\RM.Core.Application\ServiceManager.cs:line 37 at RM.Application.Test.Main.InitializationTest() in c:\TFS\Myapp\Myapp\Solutions\Myapp\RM.Application.Test\Main.cs:line 17

Commented Issue: This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original database connection has been opened and credentials have been removed from the connection string. [2229]

$
0
0
We are getting an error with no sense from EF. After we restart the IIS Application pool, we stoped getting the error which is the worst case scenario we can face.

Here is the error message:

```
Message : An error occurred while starting a transaction on the provider connection. See the inner exception for details.
Source : EntityFramework
Stack Trace : at System.Data.Entity.Core.EntityClient.EntityConnection.BeginDbTransaction(IsolationLevel isolationLevel)
at System.Data.Entity.Core.EntityClient.EntityConnection.BeginTransaction()
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction)
at System.Data.Entity.Infrastructure.DbExecutionStrategy.Execute[TResult](Func`1 operation)
at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction)
at System.Data.Entity.Internal.InternalContext.SaveChanges()
at FooBar.<UpdateAccessInformation>d__f.MoveNext() in c:\Users\FooBar\Dropbox\Foo\Foo\Foo\FooBar.cs:line 128
---- Inner Exception ----
Message : An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure.
Source : EntityFramework
Stack Trace : at System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at System.Data.Entity.Infrastructure.DefaultManifestTokenResolver.ResolveManifestToken(DbConnection connection)
at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.InternalContext.ForceOSpaceLoadingForKnownEntityTypes()
at System.Data.Entity.DbContext.System.Data.Entity.Infrastructure.IObjectContextAdapter.get_ObjectContext()
at System.Data.Entity.Infrastructure.CommitFailureHandler.BeganTransaction(DbConnection connection, BeginTransactionInterceptionContext interceptionContext)
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.BeginTransaction(DbConnection connection, BeginTransactionInterceptionContext interceptionContext)
at System.Data.Entity.Infrastructure.DbExecutionStrategy.Execute[TResult](Func`1 operation)
at System.Data.Entity.Core.EntityClient.EntityConnection.BeginDbTransaction(IsolationLevel isolationLevel)
---- Inner Exception ----
Message : The provider did not return a ProviderManifestToken string.
Source : EntityFramework
Stack Trace : at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection)
at System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection)
---- Inner Exception ----
Message : This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original database connection has been opened and credentials have been removed from the connection string. Supply an unopened connection.
Source : EntityFramework.SqlServer
Stack Trace : at System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action`1 act)
at System.Data.Entity.SqlServer.SqlProviderServices.GetDbProviderManifestToken(DbConnection connection)
at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection)
---- Inner Exception ----
Message : Login failed for user 'MY_USER_NAME'.
Source : .Net SqlClient Data Provider
Data : Key : HelpLink.ProdName Value : Microsoft SQL Server
Data : Key : HelpLink.EvtSrc Value : MSSQLServer
Data : Key : HelpLink.EvtID Value : 18456
Data : Key : HelpLink.BaseHelpUrl Value : http://go.microsoft.com/fwlink
Data : Key : HelpLink.LinkId Value : 20476
Stack Trace : at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)
at System.Data.Entity.Infrastructure.DbExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
at System.Data.Entity.Infrastructure.DbExecutionStrategy.Execute[TResult](Func`1 operation)
at System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action`1 act)
at System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action`1 act)
---- End of Exception Details ----
```

What would be causing this.

Thanks!
Comments: Hi Diego, Thanks for the response. We will try to "try" the nightlies. Is there any time frame for you guys to release this patch officially on Nuget.org feed?

Commented Issue: "Duplicate type name within an assembly" [2228]

$
0
0
Web Site project works ok with the DbContext. And I created windows forms application with the DbContext. It’s works ok too.
I think there is a problem with Windows Azure Emulator. Can anybody give me some help?

Windows 8.1 x64
Target Framework: .NET Framework 4.5.1
Windows Azure Compute Emulator has version number 2.3.0.0
Windows Azure Storage Emulator has version number 3.0.0.0

I use a "Code First" approach.

Content of «packages.config» file of «ProgressCalc» project:
---
```
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.1.0" targetFramework="net451" />
<package id="Microsoft.AspNet.Identity.Core" version="2.0.0" targetFramework="net451" />
<package id="Microsoft.AspNet.Identity.EntityFramework" version="2.0.0" targetFramework="net451" />
<package id="Microsoft.Data.Edm" version="5.6.0" targetFramework="net451" />
<package id="Microsoft.Data.OData" version="5.6.0" targetFramework="net451" />
<package id="Microsoft.Data.Services.Client" version="5.6.0" targetFramework="net451" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.3" targetFramework="net451" />
<package id="Newtonsoft.Json" version="6.0.2" targetFramework="net451" />
<package id="System.Spatial" version="5.6.0" targetFramework="net451" />
<package id="WindowsAzure.Storage" version="3.1.0.1" targetFramework="net451" />
</packages>
```
---
![Image](http://6.firepic.org/6/images/2014-04/18/2c3e8ouhonlj.png)
Comments: Luke, here is the test project in which I repeated this problem: [TEXT](https://dl.dropboxusercontent.com/u/74890074/Source/ProblemPlayback.rar)

Commented Issue: "Duplicate type name within an assembly" [2228]

$
0
0
Web Site project works ok with the DbContext. And I created windows forms application with the DbContext. It’s works ok too.
I think there is a problem with Windows Azure Emulator. Can anybody give me some help?

Windows 8.1 x64
Target Framework: .NET Framework 4.5.1
Windows Azure Compute Emulator has version number 2.3.0.0
Windows Azure Storage Emulator has version number 3.0.0.0

I use a "Code First" approach.

Content of «packages.config» file of «ProgressCalc» project:
---
```
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.1.0" targetFramework="net451" />
<package id="Microsoft.AspNet.Identity.Core" version="2.0.0" targetFramework="net451" />
<package id="Microsoft.AspNet.Identity.EntityFramework" version="2.0.0" targetFramework="net451" />
<package id="Microsoft.Data.Edm" version="5.6.0" targetFramework="net451" />
<package id="Microsoft.Data.OData" version="5.6.0" targetFramework="net451" />
<package id="Microsoft.Data.Services.Client" version="5.6.0" targetFramework="net451" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.3" targetFramework="net451" />
<package id="Newtonsoft.Json" version="6.0.2" targetFramework="net451" />
<package id="System.Spatial" version="5.6.0" targetFramework="net451" />
<package id="WindowsAzure.Storage" version="3.1.0.1" targetFramework="net451" />
</packages>
```
---
![Image](http://6.firepic.org/6/images/2014-04/18/2c3e8ouhonlj.png)
Comments: I can't edit the previous message. Click at the TEXT link.

Commented Task: Improve discoverability of Tools installer [2202]

$
0
0
Now that the Tools are available only via MS downloads, it might be an idea to add a link to the MS downloads page under each release page on this site, for example here: https://entityframework.codeplex.com/releases/view/110173 - I have come across some users having trouble finding them. (And the same page should be updated to Stable etc, I guess)
Comments: @RandRandom +1 !

Commented Issue: Database Not Being Recreated [2232]

$
0
0
Can anyone tell me why EF 6 is not recreating a database.

In VS2013 I create a simple MVC project with organizational security, on first run EF creates the database. If I delete the database and run again EF will not recreate it.

Everything I read says the default EF initilaizer creates a DB when it does not exist, which does happen the first time the code is run.

What am I missing here?
Comments: Yes I am just deleting the .MDF and .LDF files from the App_Data folder. The default connection string is _<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\fileNameHere.mdf;Initial Catalog=aspnet-SecurityDbCreationTest-20140421013801;Integrated Security=True" providerName="System.Data.SqlClient" />_ It's not a file attached to a running instance of SQL as best as I understand. When I modify the connect string to the following __<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Integrated Security=True" providerName="System.Data.SqlClient" />__ The app works but I have no idea where the database is, it does not show up in App_Data folder I am just trying to understand how/when EF creates databases. Seems nobody wants to write any real documentation anymore which i smaking this a very difficult task.

Commented Issue: "Duplicate type name within an assembly" [2228]

$
0
0
Web Site project works ok with the DbContext. And I created windows forms application with the DbContext. It’s works ok too.
I think there is a problem with Windows Azure Emulator. Can anybody give me some help?

Windows 8.1 x64
Target Framework: .NET Framework 4.5.1
Windows Azure Compute Emulator has version number 2.3.0.0
Windows Azure Storage Emulator has version number 3.0.0.0

I use a "Code First" approach.

Content of «packages.config» file of «ProgressCalc» project:
---
```
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.1.0" targetFramework="net451" />
<package id="Microsoft.AspNet.Identity.Core" version="2.0.0" targetFramework="net451" />
<package id="Microsoft.AspNet.Identity.EntityFramework" version="2.0.0" targetFramework="net451" />
<package id="Microsoft.Data.Edm" version="5.6.0" targetFramework="net451" />
<package id="Microsoft.Data.OData" version="5.6.0" targetFramework="net451" />
<package id="Microsoft.Data.Services.Client" version="5.6.0" targetFramework="net451" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.3" targetFramework="net451" />
<package id="Newtonsoft.Json" version="6.0.2" targetFramework="net451" />
<package id="System.Spatial" version="5.6.0" targetFramework="net451" />
<package id="WindowsAzure.Storage" version="3.1.0.1" targetFramework="net451" />
</packages>
```
---
![Image](http://6.firepic.org/6/images/2014-04/18/2c3e8ouhonlj.png)
Comments: Exception rises only when you in a step-by-step debug mode.

Created Unassigned: Many-to-Many Relationship and explicitly loading with OrderBy doesn't work [2234]

$
0
0
Entity Framework Version 6.1

My example is: [Configuring a Many-to-Many Relationship](http://msdn.microsoft.com/en-us/data/jj591620#ManyToMany)

When I use: [Applying filters when explicitly loading related entities](http://msdn.microsoft.com/en-us/data/jj574232#explicitFilter)
```
context.Entry(course).Collection(c => c.Instructors).Query().OrderBy(i => i.FirstName).Load();
```
There are no instructors charged, even though it has three records in the database.

When I use: [Explicitly Loading](http://msdn.microsoft.com/en-us/data/jj574232#explicit)
```
context.Entry(course).Collection(c => c.Instructors).Load();
```
The three instructors are loaded, but unsorted.

A One-to-Many Relationship and explicitly loading with OrderBy works fine.

With the attached project this behavior can be traced.

Commented Issue: Database Not Being Recreated [2232]

$
0
0
Can anyone tell me why EF 6 is not recreating a database.

In VS2013 I create a simple MVC project with organizational security, on first run EF creates the database. If I delete the database and run again EF will not recreate it.

Everything I read says the default EF initilaizer creates a DB when it does not exist, which does happen the first time the code is run.

What am I missing here?
Comments: Thanks Diego, you were correct, deleting just the .MDF was leaving things registered in (LocalDb). You used to not be able to delete SQL database files. This fact along with EF automagically creating things for you led me to believe I could just delete the files and they shoul dbe recreated. In the old days we could not delete SQL data files that belong to an instance of SQL. I've spent better than a day now trying to figure out something so friggin simple. I think the EF folks are violating some core programming rules nowadays. Combining database creation and migration logic with the model programming SDK is just making things more difficult not better.

Commented Issue: Entity Framework Duplicate type name within an assembly (6.1.0) [2231]

$
0
0
I am not sure what is going on but I keep getting the following exception when doing a query. "Duplicate type name within an assembly." I had resolved the issue by removing entity framework from all the projects in the solutions and re-installing using nugget. Then all of the sudden the exception is back. I have verified my table schema over and over and find nothing wrong with. The issue keeps coming back and I have to keep repeating the steps mentioned above to resolve.

This is the query causing the exception.

```
var BaseQuery = from Users in db.Users
join UserInstalls in db.UserTenantInstalls on Users.ID equals UserInstalls.UserID
join Installs in db.TenantInstalls on UserInstalls.TenantInstallID equals Installs.ID
where
Users.Username == Username
&& Users.Password == Password
&& Installs.Name == Install
select Users;

var Query = BaseQuery.Include("UserTenantInstalls.TenantInstall");

return Query.FirstOrDefault();

```

Comments: This appears to be a dupe of [Issue 2228](https://entityframework.codeplex.com/workitem/2228) as the stack traces are identical up until we get to user code. I'm closing this issue and remaining work will be tracked on 2228. @CodeMilian I encourage you to upvote the other issue

Commented Issue: [back compat] Designer: Error opening EF5 edmx with decimal precision in EF6 designer [1653]

$
0
0
Issue reported via Connect - http://connect.microsoft.com/VisualStudio/feedback/details/800178/cannot-load-mymodel-edmx-specified-cast-is-not-valid-when-clicking-edmx-file-in-project

EF is using a singleton object of the internal Unbounded type for unbounded facet values. To check if a facet is unbounded you just do a reference comparison to the singleton instance. The LegacyProviderManifestWrapper translates EF5 metadata types to EF6 metadata types and vice versa. When doing the conversion we used the wrong (e.g. the one defined in EF6 (EntityFramework.dll) rather than the one defined in EF5 (System.Data.Entity.dll)) reference for checking if the facet value is unbounded. This resulted in not recognizing Unbounded value and led to casting the instance of Unbounded type to byte which caused the InvalidCastException.

This was already reported twice after VS2012 RC was shipped. In one case it is impossible to open an edmx file. In the other case it is impossible to import functions - in both cases the culprit seems to be a decimal parameter in a stored proc.
Comments: @moozzyk, @Falagard - after much effort (which included setting up a new laptop with VS2012 and EF6.1), I added an entry to my legacy EF5 EDMX. In the section ``` <!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) --> <edmx:Designer> <edmx:Options> <DesignerInfoPropertySet> ``` I added the following which seemed to have resolved my issue. I am now able to open an older EF5 EDMX within the EF6.1 designer tooling. This somehow does not make sense to considering the comment made in https://entityframework.codeplex.com/discussions/470300 ``` <DesignerProperty Name="UseLegacyProvider" Value="false" /> ```

Closed Issue: Entity Framework Duplicate type name within an assembly (6.1.0) [2231]

$
0
0
I am not sure what is going on but I keep getting the following exception when doing a query. "Duplicate type name within an assembly." I had resolved the issue by removing entity framework from all the projects in the solutions and re-installing using nugget. Then all of the sudden the exception is back. I have verified my table schema over and over and find nothing wrong with. The issue keeps coming back and I have to keep repeating the steps mentioned above to resolve.

This is the query causing the exception.

```
var BaseQuery = from Users in db.Users
join UserInstalls in db.UserTenantInstalls on Users.ID equals UserInstalls.UserID
join Installs in db.TenantInstalls on UserInstalls.TenantInstallID equals Installs.ID
where
Users.Username == Username
&& Users.Password == Password
&& Installs.Name == Install
select Users;

var Query = BaseQuery.Include("UserTenantInstalls.TenantInstall");

return Query.FirstOrDefault();

```

Comments: Dupe of [Issue 2228](https://entityframework.codeplex.com/workitem/2228)

Commented Issue: "Duplicate type name within an assembly" [2228]

$
0
0
Web Site project works ok with the DbContext. And I created windows forms application with the DbContext. It’s works ok too.
I think there is a problem with Windows Azure Emulator. Can anybody give me some help?

Windows 8.1 x64
Target Framework: .NET Framework 4.5.1
Windows Azure Compute Emulator has version number 2.3.0.0
Windows Azure Storage Emulator has version number 3.0.0.0

I use a "Code First" approach.

Content of «packages.config» file of «ProgressCalc» project:
---
```
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.1.0" targetFramework="net451" />
<package id="Microsoft.AspNet.Identity.Core" version="2.0.0" targetFramework="net451" />
<package id="Microsoft.AspNet.Identity.EntityFramework" version="2.0.0" targetFramework="net451" />
<package id="Microsoft.Data.Edm" version="5.6.0" targetFramework="net451" />
<package id="Microsoft.Data.OData" version="5.6.0" targetFramework="net451" />
<package id="Microsoft.Data.Services.Client" version="5.6.0" targetFramework="net451" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.3" targetFramework="net451" />
<package id="Newtonsoft.Json" version="6.0.2" targetFramework="net451" />
<package id="System.Spatial" version="5.6.0" targetFramework="net451" />
<package id="WindowsAzure.Storage" version="3.1.0.1" targetFramework="net451" />
</packages>
```
---
![Image](http://6.firepic.org/6/images/2014-04/18/2c3e8ouhonlj.png)
Comments: I have the same problem and also like Neocriss said. Only when you don't debug. When you start with "CTRL + F5" , no problem.... I am working with a local database! I created my edmx from the database...

Commented Issue: Database Not Being Recreated [2232]

$
0
0
Can anyone tell me why EF 6 is not recreating a database.

In VS2013 I create a simple MVC project with organizational security, on first run EF creates the database. If I delete the database and run again EF will not recreate it.

Everything I read says the default EF initilaizer creates a DB when it does not exist, which does happen the first time the code is run.

What am I missing here?
Comments: Mike, thanks for the feedback. Ideally EF should recover gracefully from the state in which the database is registered in LocalDb but the files no longer exist on disk. We have an [existing bug for that](https://entityframework.codeplex.com/workitem/1748) and I am going to close this one as a duplicate. Feel free to cast your vote on the other issue. We keep making improvements in this area, e.g. we recently revised the logic to check for database existence to make it more robust (see [this commit](https://entityframework.codeplex.com/SourceControl/changeset/18217e6567add90e9f58ebdf9b97e5218e3ee957) as an example), but the matrix is quite complex across the different editions of SQL Server (with connection strings containing AttachDbFile and without it, and with Initial Catalog specified and without it) and other providers. Anyway, I think you are right that a programing model that is more explicit about database creation can be easier to understand when things go wrong. We will keep your feedback in mind for the future.

Commented Issue: Application fails when attached mdf and ldf files are deleted [1748]

$
0
0
When using attached databases in SQL Express or LocalDB it is very common to want to delete the database by deleting the files directly from the file system. This may be something that the developer does manually expecting it to work or that a tool, e.g. "git clean", can do automatically.

Unfortunately because of how database registration works in SQL Server, the next time you try to do anything with that database (e.g. checking for existence or trying to create it again) it will fail, although subsequent retries will succeed.

We do have some code already that performs retries and follow different heuristics to try to get consistent behavior in these database methods. We could add additional retry logic to handle this scenario more smoothly.
Comments: Closing [#2232](https://entityframework.codeplex.com/workitem/2232) as a duplicate of this item.

Closed Issue: Database Not Being Recreated [2232]

$
0
0
Can anyone tell me why EF 6 is not recreating a database.

In VS2013 I create a simple MVC project with organizational security, on first run EF creates the database. If I delete the database and run again EF will not recreate it.

Everything I read says the default EF initilaizer creates a DB when it does not exist, which does happen the first time the code is run.

What am I missing here?
Comments: Duplicate of [#1748](https://entityframework.codeplex.com/workitem/1748)

Edited Issue: [Stress] Non-recurring Read error should be investigated [2213]

$
0
0
One of our performance bugs failed today with the following error message:

```
Query_Execution_TPT_model_Funcletization_Case1_WithMember_DisableMultipleActiveResultSets_Funcletization50000Iterations

System.Data.Entity.Core.EntityCommandExecutionException: Calling 'Read' when the data reader is closed is not a valid operation. ---> System.Data.SqlClient.SqlException: A severe error occurred on the current command. The results, if any, should be discarded.
A severe error occurred on the current command. The results, if any, should be discarded.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryHasMoreRows(Boolean& moreRows)
at System.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean setTimeout, Boolean& more)
at System.Data.SqlClient.SqlDataReader.Read()
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.StoreRead() in c:\TeamCity\buildAgent\work\af13cf986dd509e9\src\EntityFramework\Core\Common\internal\materialization\Shaper`.cs:line 192
--- End of inner exception stack trace ---
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.HandleReaderException(Exception e) in c:\TeamCity\buildAgent\work\af13cf986dd509e9\src\EntityFramework\Core\Common\internal\materialization\Shaper`.cs:line 231
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.StoreRead() in c:\TeamCity\buildAgent\work\af13cf986dd509e9\src\EntityFramework\Core\Common\internal\materialization\Shaper`.cs:line 200
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext() in c:\TeamCity\buildAgent\work\af13cf986dd509e9\src\EntityFramework\Core\Common\internal\materialization\Shaper`.cs:line 315
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at QueryExecution.QueryExecutionBase.Funcletization_Case1_WithMember(DefaultContainer context) in c:\TeamCity\buildAgent\work\af13cf986dd509e9\test\EntityFramework\Reliability\PerformanceTests\QueryExecution\QueryExecution.Funcletization.cs:line 26
```
This is not a recurring error as it’s the first time I see this. This is indicative of either an environment degradation (such as SQL Server or network conditions or the OS), or of a potential bug that only shows under stress conditions. We should investigate and make sure this is covered by a stress test.

Commented Issue: [back compat] Designer: Error opening EF5 edmx with decimal precision in EF6 designer [1653]

$
0
0
Issue reported via Connect - http://connect.microsoft.com/VisualStudio/feedback/details/800178/cannot-load-mymodel-edmx-specified-cast-is-not-valid-when-clicking-edmx-file-in-project

EF is using a singleton object of the internal Unbounded type for unbounded facet values. To check if a facet is unbounded you just do a reference comparison to the singleton instance. The LegacyProviderManifestWrapper translates EF5 metadata types to EF6 metadata types and vice versa. When doing the conversion we used the wrong (e.g. the one defined in EF6 (EntityFramework.dll) rather than the one defined in EF5 (System.Data.Entity.dll)) reference for checking if the facet value is unbounded. This resulted in not recognizing Unbounded value and led to casting the instance of Unbounded type to byte which caused the InvalidCastException.

This was already reported twice after VS2012 RC was shipped. In one case it is impossible to open an edmx file. In the other case it is impossible to import functions - in both cases the culprit seems to be a decimal parameter in a stored proc.
Comments: @ahmadm - when you do that the designer internally use the real EF6 provider to do the work. When the setting is not there or the Value is true the designer uses a wrapping provider which exposes EF5 provider as an EF6 provider and the bug is in this wrapping provider. One issue might have is that when you update the model from the database and you are using Sql Server 2012 the SSDL will contain "2012" as the provider manifest token value which was not supported in EF5. Which will make your app fail at runtime.

Edited Feature: Allow Set and Set(Type) methods to be overridden [2071]

$
0
0
From this pull request: http://entityframework.codeplex.com/SourceControl/network/forks/ErikSchierboom/testabledbset/contribution/6107

At the moment, it is possible to define the various `DbSet<T>` properties in a `DbContext` as virtual, which allows them to be unit tested (see http://msdn.microsoft.com/en-us/data/dn314429.aspx#limitations). However, it is not uncommon for people to have a base `Repository<T>` class which uses the `Set<T>` method of the `DbContext` class to get the correct `DbSet` for the repository's type. Unfortunately, this method is not `virtual` which means that it cannot be easily mocked.
Viewing all 10318 articles
Browse latest View live




Latest Images