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

Edited Unassigned: InvalidOperationException was thrown when instantiate a DbContext after DbGeography.PointFromText [2827]

$
0
0
InvalidOperationException was thrown when run the following code.

```cs
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Spatial;

namespace EFTest
{
public class MyDbConfiguration : DbConfiguration { }

[DbConfigurationType(typeof(MyDbConfiguration))]
public partial class EFTestEntities { }

class Program
{
static void Main(string[] args)
{
var geo = DbGeography.PointFromText("POINT(90 90)", DbGeography.DefaultCoordinateSystemId);
using (var context = new EFTestEntities()) // throw InvalidOperationException
{
// some operation
}
}
}
}
```

![Image](https://www.codeplex.com/Download/AttachmentDownload.ashx?ProjectName=entityframework&WorkItemId=2827&FileAttachmentId=1490951)

Thrown InvalidOperationException:

```
System.InvalidOperationException was unhandled
HResult=-2146233079
Message=The default DbConfiguration instance was used by the Entity Framework before the 'MyDbConfiguration' type was discovered. An instance of 'MyDbConfiguration' must be set at application start before using any Entity Framework features or must be registered in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=260883 for more information.
Source=EntityFramework
StackTrace:
at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForAssembly(Assembly assemblyHint, Type contextTypeHint)
at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForContext(Type contextType)
at System.Data.Entity.DbContext.InitializeLazyInternalContext(IInternalConnection internalConnection, DbCompiledModel model)
at System.Data.Entity.DbContext..ctor(String nameOrConnectionString)
at EFTest.EFTestEntities..ctor() at d:\EFTest\EFTest\EFTestEntities.Context.cs:line 18
at EFTest.Program.Main(String[] args) at d:\EFTest\EFTest\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
```

Environment
.NET: 4.5
EF: 6.1.3
VS: 2012

Workaround:

```cs
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Spatial;

namespace EFTest
{
public class MyDbConfiguration : DbConfiguration { }

[DbConfigurationType(typeof(MyDbConfiguration))]
public partial class EFTestEntities { }

class Program
{
static void Main(string[] args)
{
using (var context = new EFTestEntities())
{
var geo = DbGeography.PointFromText("POINT(90 90)", DbGeography.DefaultCoordinateSystemId);
// some operation
}
}
}
}
```

Does anyone have any suggestions?

Edited Task: UpForGrabs: Increasing details in the exception of model validation [2824]

$
0
0
System.Data.Entity.ModelConfiguration.ModelValidationException

__"Name: Each property name in a type must be unique. Property name 'xxx' is already defined"__

Could be possible to add more details to model validation exceptions?
Please, put a look at this.

http://shepardroad.com/2015/06/avoiding-an-entity-framework-rabbit-hole/

I had the same problem.
Thx

Commented Task: UpForGrabs: Increasing details in the exception of model validation [2824]

$
0
0
System.Data.Entity.ModelConfiguration.ModelValidationException

__"Name: Each property name in a type must be unique. Property name 'xxx' is already defined"__

Could be possible to add more details to model validation exceptions?
Please, put a look at this.

http://shepardroad.com/2015/06/avoiding-an-entity-framework-rabbit-hole/

I had the same problem.
Thx
Comments: Agreed it would be good to include the entity type name. Marking as UpForGrabs as this would make a good contribution.

Edited Unassigned: EF Rollback failure : null connection [2815]

$
0
0

Hi,

I have a service that uses EF and EF.bulkInsert plugin to do some db operation. There is a failure with the rollback operation that I couldn't understand.

Here is a brief structure of the code:

```
{
public void BulkUpdate(Guid ObjectId, Object newObject)
{

using (var dbContextTransaction = this.Context.Database.BeginTransaction())
{
try
{
DbSetting.SuspendExecutionStrategy = true;
this.UpdateObjectWithBulkOperation(ObjectId, newObject, dbContextTransaction.UnderlyingTransaction);

dbContextTransaction.Commit();
}
catch (Exception)
{
dbContextTransaction.Rollback();
throw;
}
finally
{
DbSetting.SuspendExecutionStrategy = false;
}
}
}
}
```

Here is the error:

"faultDetail": ": InternalServerError : An internal server error occurred while processing the operation. : {
: UnknownInternalFailure : The service has encountered an unknown internal server error: System.Data.Entity.Core.EntityException: The underlying provider failed on Rollback. --->
System.ArgumentNullException: Value cannot be null.
Parameter name: connection
at System.Data.Entity.Utilities.Check.NotNull[T](T value, String parameterName)
at System.Data.Entity.Infrastructure.Interception.DbTransactionDispatcher.Rollback(DbTransaction transaction, DbInterceptionContext interceptionContext)
at System.Data.Entity.Core.EntityClient.EntityTransaction.Rollback()
--- End of inner exception stack trace ---
at System.Data.Entity.Core.EntityClient.EntityTransaction.Rollback()
at .SomeDao.BulkUpdate(...)

a...

at lambda_method(Closure , Object , Object[] )

at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass12.b__8(Object instance, Object[] methodParameters)

at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)

--- End of stack trace from previous location where exception was thrown ---

at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

at System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

at System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

at System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

at System.Web.Http.Filters.ActionFilterAttribute.d__0.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

The error should that the conncetion is null when executing hte below method for rollback:
{
From: DbTransactionInterceptionContext.cs:
public DbTransactionInterceptionContext WithConnection(DbConnection connection)
{
Check.NotNull(connection, "connection");

var transactionInterceptionContext = TypedClone();
transactionInterceptionContext._connection = connection;

return transactionInterceptionContext;
}

}

But what could cause the error?

Commented Unassigned: EF Rollback failure : null connection [2815]

$
0
0

Hi,

I have a service that uses EF and EF.bulkInsert plugin to do some db operation. There is a failure with the rollback operation that I couldn't understand.

Here is a brief structure of the code:

```
{
public void BulkUpdate(Guid ObjectId, Object newObject)
{

using (var dbContextTransaction = this.Context.Database.BeginTransaction())
{
try
{
DbSetting.SuspendExecutionStrategy = true;
this.UpdateObjectWithBulkOperation(ObjectId, newObject, dbContextTransaction.UnderlyingTransaction);

dbContextTransaction.Commit();
}
catch (Exception)
{
dbContextTransaction.Rollback();
throw;
}
finally
{
DbSetting.SuspendExecutionStrategy = false;
}
}
}
}
```

Here is the error:

"faultDetail": ": InternalServerError : An internal server error occurred while processing the operation. : {
: UnknownInternalFailure : The service has encountered an unknown internal server error: System.Data.Entity.Core.EntityException: The underlying provider failed on Rollback. --->
System.ArgumentNullException: Value cannot be null.
Parameter name: connection
at System.Data.Entity.Utilities.Check.NotNull[T](T value, String parameterName)
at System.Data.Entity.Infrastructure.Interception.DbTransactionDispatcher.Rollback(DbTransaction transaction, DbInterceptionContext interceptionContext)
at System.Data.Entity.Core.EntityClient.EntityTransaction.Rollback()
--- End of inner exception stack trace ---
at System.Data.Entity.Core.EntityClient.EntityTransaction.Rollback()
at .SomeDao.BulkUpdate(...)

a...

at lambda_method(Closure , Object , Object[] )

at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass12.b__8(Object instance, Object[] methodParameters)

at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)

--- End of stack trace from previous location where exception was thrown ---

at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

at System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

at System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

at System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

at System.Web.Http.Filters.ActionFilterAttribute.d__0.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

The error should that the conncetion is null when executing hte below method for rollback:
{
From: DbTransactionInterceptionContext.cs:
public DbTransactionInterceptionContext WithConnection(DbConnection connection)
{
Check.NotNull(connection, "connection");

var transactionInterceptionContext = TypedClone();
transactionInterceptionContext._connection = connection;

return transactionInterceptionContext;
}

}

But what could cause the error?
Comments: __EF Team Triage:__ This issue is lacking enough information for us to be able to effectively triage it. For a guide on submitting good bug reports, read_ [Painless Bug Tracking](http://www.joelonsoftware.com/articles/fog0000000029.html). _The most important elements to help us act on a bug report are example code/steps that reproduce the issue, the outcome/results you are expecting, and the results or error message that you are receiving. Following are a few questions to help us understand this bug report, for future issues please try to include this info in the initial report._ Could you share a complete code listing (or a project) that we can use to reproduce and debug the issue you are seeing? From the code listing provided we can not see how the context is being created, what `UpdateObjectWithBulkOperation` does, etc.

Closed Unassigned: In EF6, when using TPT inheritance mapping and querying for base class properties only, JOINs for all derived classes are included in the query if at least one child collection of the base class is included [2814]

$
0
0
I have three classes:
```C#
public class EntityBase
{
public Guid Id { get; set; }

[MaxLength(50)]
public string Name { get; set; }

public List<Tag> Tags { get; set; }
}

[Table("DerivedEntities1")]
public class DerivedEntity1 : EntityBase
{
[MaxLength(50)]
public string Text { get; set; }
}

[Table("DerviedEntities2")]
public class DerivedEntity2 : EntityBase
{
public int Score { get; set; }
}
```

If I query for base entities and project only plain properties (Name, for example) - everything is fine, derived classes are not joined to the query, since no information is needed from them

```C#
var entities = dataContext.Entities
.Select(e => new { Name = e.Name })
.ToList();
```
```sql
SELECT
1 AS [C1],
[Extent1].[Name] AS [Name]
FROM [dbo].[EntityHeaders] AS [Extent1]
```

However, if I need to fetch a collection for the base class, tables for all derived classes appear in the query.
```c#
var entities = dataContext.Entities
.Include(e => e.Tags)
.Select(e => new { Name = e.Name, Tags = e.Tags })
.ToList();
```
```sql
SELECT
[Project1].[Id1] AS [Id],
[Project1].[Id2] AS [Id1],
[Project1].[Id] AS [Id2],
[Project1].[C1] AS [C1],
[Project1].[Name] AS [Name],
[Project1].[C2] AS [C2],
[Project1].[Id3] AS [Id3],
[Project1].[Value] AS [Value],
[Project1].[EntityBase_Id] AS [EntityBase_Id]
FROM ( SELECT
[Extent1].[Id] AS [Id],
[Extent1].[Name] AS [Name],
[Extent2].[Id] AS [Id1],
[Extent3].[Id] AS [Id2],
1 AS [C1],
[Extent4].[Id] AS [Id3],
[Extent4].[Value] AS [Value],
[Extent4].[EntityBase_Id] AS [EntityBase_Id],
CASE WHEN ([Extent4].[Id] IS NULL) THEN CAST(NULL AS int) ELSE 1 END AS [C2]
FROM [dbo].[EntityHeaders] AS [Extent1]
LEFT OUTER JOIN [dbo].[DerivedEntities2] AS [Extent2] ON [Extent1].[Id] = [Extent2].[Id]
LEFT OUTER JOIN [dbo].[DerivedEntities1] AS [Extent3] ON [Extent1].[Id] = [Extent3].[Id]
LEFT OUTER JOIN [dbo].[Tags] AS [Extent4] ON [Extent1].[Id] = [Extent4].[EntityBase_Id]
) AS [Project1]
ORDER BY [Project1].[Id1] ASC, [Project1].[Id2] ASC, [Project1].[Id] ASC, [Project1].[C2] ASC
```
Is there any possibility to avoid this?
Comments: **EF Team Triage:** We agree that the additional joins do not technically need to be included. Unfortunately given the complexity and time needed for changes such as this, along with the high risk of breaking other queries, this is not something our team is going to address.

Closed Unassigned: LINQ to SQL String.IsNullOrEmpty(" ") Returns True [2826]

$
0
0

VB.NET considers `String.IsNullOrEmpty(" ")` to be `False` however once the code is converted to SQL, it evaluates to `True`

```
Debug.Print(String.IsNullOrEmpty(" ").ToString())
' ==> False

Dim SpaceQry = DB.TheTable _
.Where(Function(DbRow) String.IsNullOrEmpty(" "))

Debug.Print(SpaceQry.Count().ToString())
' ==> Same as SELECT COUNT(*) FROM TheTable
```

Resulting SQL

```
WHERE (N' ' IS NULL) OR (( CAST(LEN(N' ') AS int)) = 0)
```

The core of the issue is that `CAST(LEN(N' ') AS int)` __Does = 0__
Comments: See discussion

Closed Unassigned: Can't Connect to DB with _ underscore in db name [2832]

$
0
0
I have a database named: LA_ARI

I'm unable to connect to this database.

I can connect to any other database that does not have an underscore ( _ ) in the db name.

Does EF support connecting to databases with an underscore in the name?


Comments: See discussion

Edited Unassigned: Unable to cast object of type 'System.Data.Entity.Core.Query.InternalTrees.SortOp' to type 'System.Data.Entity.Core.Query.InternalTrees.ProjectOp [2834]

$
0
0
Unable to cast object of type 'System.Data.Entity.Core.Query.InternalTrees.SortOp' to type 'System.Data.Entity.Core.Query.InternalTrees.ProjectOp.

Getting this when running the query:

return ctx.Users.Where(u => u.Username == username).Select(u => new ApplicationDescriptor()
{
Pages = u.Pages.
Select(p => new {
Name = p.Name,
Title = p.Title,
ModuleNames = p.Modules.Where(m => (m.Module.Views & applicableView) != 0 && m.Module.Users.Any(v => v.Username == username)).OrderBy(m => m.SortOrder).Select(m => m.Module.Name),
SubMenuIsApplicable = (p.SubMenu.Views & applicableView) != 0 && p.SubMenu.Users.Any(v => v.Username == username),
SubMenuName = p.SubMenu.Name }).
Where(p => p.ModuleNames.Any() || p.SubMenuIsApplicable).
Select(p => new PageDescriptor()
{
Name = p.Name,
Title = p.Title,
ModuleNames = p.ModuleNames,
SubMenuName = p.SubMenuIsApplicable ? p.SubMenuName : null
}),

Modules = u.Modules.Where(m => (m.Views & applicableView) != 0).Select(m => new ModuleDescriptor() { Name = m.Name })

}).First();


Some classes:

public class User
{
public virtual string Username { get; set; }
public virtual string UICultureName { get; set; }
public virtual ICollection<Page> Pages { get; set; }
public virtual ICollection<Module> Modules { get; set; }
}

public class Page
{
public virtual string Name { get; set; }
public virtual string Title { get; set; }
public virtual ICollection<User> Users { get; set; }
public virtual ICollection<ModuleWithSortOrder> Modules { get; set; }
public virtual Module SubMenu { get; set; }
}

public class Module
{
public virtual string Name { get; set; }
public virtual View Views { get; set; }
public virtual ICollection<User> Users { get; set; }
public virtual ICollection<ModuleWithSortOrder> SortOrders { get; set; }
public virtual ICollection<Page> SubMenuPages { get; set; }
}

public class ModuleWithSortOrder
{
public virtual int Id { get; set; }
public virtual Module Module { get; set; }
public virtual int SortOrder { get; set; }
public virtual ICollection<Page> Pages { get; set; }
}

[Flags]
public enum View
{
Mobile = 1,
Pad = 2,
Desktop = 4
}


Stack trace:

at System.Data.Entity.Core.Query.PlanCompiler.NestPullup.Visit(ExistsOp op, Node n)
at System.Data.Entity.Core.Query.InternalTrees.ExistsOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitChildren(Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitDefault(Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitScalarOpDefault(ScalarOp op, Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.Visit(ConditionalOp op, Node n)
at System.Data.Entity.Core.Query.InternalTrees.ConditionalOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitChildren(Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitDefault(Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitScalarOpDefault(ScalarOp op, Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.Visit(ConditionalOp op, Node n)
at System.Data.Entity.Core.Query.InternalTrees.ConditionalOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitChildren(Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitDefault(Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitScalarOpDefault(ScalarOp op, Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.Visit(ConditionalOp op, Node n)
at System.Data.Entity.Core.Query.InternalTrees.ConditionalOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitChildren(Node n)
at System.Data.Entity.Core.Query.PlanCompiler.NestPullup.Visit(FilterOp op, Node n)
at System.Data.Entity.Core.Query.InternalTrees.FilterOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitChildren(Node n)
at System.Data.Entity.Core.Query.PlanCompiler.NestPullup.Visit(ProjectOp op, Node n)
at System.Data.Entity.Core.Query.InternalTrees.ProjectOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitChildren(Node n)
at System.Data.Entity.Core.Query.PlanCompiler.NestPullup.Visit(PhysicalProjectOp op, Node n)
at System.Data.Entity.Core.Query.InternalTrees.PhysicalProjectOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitChildren(Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitDefault(Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitScalarOpDefault(ScalarOp op, Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.Visit(CollectOp op, Node n)
at System.Data.Entity.Core.Query.InternalTrees.CollectOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitChildren(Node n)
at System.Data.Entity.Core.Query.PlanCompiler.NestPullup.Visit(VarDefOp op, Node n)
at System.Data.Entity.Core.Query.InternalTrees.VarDefOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitChildren(Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitDefault(Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitAncillaryOpDefault(AncillaryOp op, Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.Visit(VarDefListOp op, Node n)
at System.Data.Entity.Core.Query.InternalTrees.VarDefListOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitChildren(Node n)
at System.Data.Entity.Core.Query.PlanCompiler.NestPullup.Visit(ProjectOp op, Node n)
at System.Data.Entity.Core.Query.InternalTrees.ProjectOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitChildren(Node n)
at System.Data.Entity.Core.Query.PlanCompiler.NestPullup.Visit(ConstrainedSortOp op, Node n)
at System.Data.Entity.Core.Query.InternalTrees.ConstrainedSortOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitChildren(Node n)
at System.Data.Entity.Core.Query.PlanCompiler.NestPullup.Visit(PhysicalProjectOp op, Node n)
at System.Data.Entity.Core.Query.InternalTrees.PhysicalProjectOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
at System.Data.Entity.Core.Query.PlanCompiler.NestPullup.Process()
at System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Compile(List`1& providerCommands, ColumnMap& resultColumnMap, Int32& columnCount, Set`1& entitySets)
at System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Compile(DbCommandTree ctree, List`1& providerCommands, ColumnMap& resultColumnMap, Int32& columnCount, Set`1& entitySets)
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition..ctor(DbProviderFactory storeProviderFactory, DbCommandTree commandTree, DbInterceptionContext interceptionContext, IDbDependencyResolver resolver, BridgeDataReaderFactory bridgeDataReaderFactory, ColumnMapFactory columnMapFactory)

Let me know if more info is needed.

Regards,

Emil Müller

Edited Unassigned: SerializationException even for Serializable exceptions [2836]

$
0
0
When running the command-line migrate tool through the Package Manager Console (e.g. "Update-Database" or "Add-MIgration" command) and a custom exception happens, I get this code:

```
System.Runtime.Serialization.SerializationException: Type is not resolved for member 'Foo.CustomException,Foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
```

This makes it impossible to debug the exception. But the problem is that the CustomException is actually serializable:

```
[Serializable]
public class CustomException : Exception
{
public CustomException() { }
public CustomException(string message) : base(message) { }
public CustomException(string message, Exception innerException) : base(message, innerException) { }
protected CustomException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
```

I've been trying to find the problem and design a custom exception that would get shown in the Package Manager Console, but I wasn't successful.

My question is: __How should the custom exception look like so it would appear in the Package Manager Console when it happens?__ What am I missing there? Why is the custom exception still not serializing correctly?

When I throw normal exception (`Exception` class), it gets displayed properly. Why does my `CustomException` class not?

Closed Unassigned: Managing DbContext the right way with Entity Framework [2835]

$
0
0
Hi, thank you for this great version.
It would be nice to have another level of easiness ans compactness, and more toward effeciency when contacting the DB, by having a look at Mr. Mehdi el Gueddari project and Idea:

http://mehdi.me/ambient-dbcontext-in-ef6

https://github.com/mehdime/DbContextScope

and contacting him to have some of his ideas in EF.

Comments: This as cross-posted to https://github.com/aspnet/EntityFramework/issues/3402

Commented Unassigned: Wierd StackOverflow Exception Encountered [2817]

$
0
0
We've encountered a stack overflow exception randomly in one instance of our applications, on code that has been stable with plenty of usage. Using the Debug Diagnostic tool, the thread that caused the overflow has a stacktrace almost entirely within the EF callstack. We've spent countless hours trying to find where in our codebase the stack overflow may have been caused, but have been unsuccessful in identifying a possible culprit.

Looking at the attached stack trace - is there a way to find out what type of query or query inputs would be the culprit?
Comments: Ok we thought it may have been due to an issue we fixed in 6.1.3... but clearly not :) Could you also try switching `context.Configuration.UseDatabaseNullSemantics` to `false` and see if you still get the exception? If you do still get it, can you provide a code listing that we can use to reproduce the issue?

Commented Unassigned: An instance of 'ContextConfiguration' was set but this type was not discovered in the same assembly as the 'MyDbContext' context [2821]

$
0
0
I have a few DbContexts in different assemblies. All of them are marked with [DbConfigurationType(typeof(ContextConfiguration))] and this works just fine.

Now I need to introduce another configuration for one of DbContexts. I create a new MySpecialDbConfiguration class in the same assembly as the context. I put [DbConfigurationType(typeof(MySpecialDbConfiguration))] on top of that special assembly. And I get exception:

> An instance of 'MySpecialDbConfiguration' was set but this type was not discovered in the same assembly as the 'MyOldNotSpecialContext' context. Either put the DbConfiguration type in the same assembly as the DbContext type, use DbConfigurationTypeAttribute on the DbContext type to specify the DbConfiguration type, or set the DbConfiguration type in the config file

But I am setting all configuration types through DbConfigurationTypeAttribute. Am I doing something wrong?
Comments: Unfortunately you can only have one `DbConfiguration` per `AppDomain` - meaning you can't have a configuration for each context type. This is a limitation inherent in the design of `DbConfiguration` and the reason we are taking a different approach to config in EF7.

Closed Unassigned: COALESCE column in view generates a nullable entity property [2833]

$
0
0
When I use COALESCE in a View EF creates a nullable property for the entity. For ISNULL EF correctly creates a not nullable property.

Example scenario:

CREATE VIEW dbo.vwExample
AS
SELECT
Id,
COALESCE(one.Value, two.Value, three.Value, '') AS Value
FROM dbo.Table AS t
LEFT JOIN dbo.TableVarOne AS one ON ..
LEFT JOIN dbo.TableVarTwo AS two ON ..
LEFT JOIN dbo.TableVarThree AS three ON ..
Comments: This is because SQL Server metadata is telling EF that the column is nullable. This is correct because `COALESCE` doesn't guarantee that the result will be null, it just means if the first value is null it will be replaced by the second (which could be null).

Commented Unassigned: Crashes when executing an Expression predicate [2837]

$
0
0
The code below will die in runtime (error, code below). The problem lies in Where condition and is related to master table (Product). If I to pv != null then it works but as soon as I try to use master table (Product) it dies.

> There is already an open DataReader associated with this Command which must be closed first.

> at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
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.DataClasses.EntityReference`1.Load(MergeOption mergeOption)
at System.Data.Entity.Core.Objects.DataClasses.RelatedEnd.DeferredLoad()
at System.Data.Entity.Core.Objects.Internal.LazyLoadBehavior.LoadProperty[TItem](TItem propertyValue, String relationshipName, String targetRoleName, Boolean mustBeNull, Object wrapperObject)
at System.Data.Entity.Core.Objects.Internal.LazyLoadBehavior.<>c__DisplayClass7`2.<GetInterceptorDelegate>b__2(TProxy proxy, TItem item)
at System.Data.Entity.DynamicProxies.ProductValue_16D9978CB4F6B2319AED4EB8753DB9CC5429F06DC6BA384FAA6EB2533DB293DD.get_Product()
at lambda_method(Closure , ProductValue )
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)
at UserQuery.<>c__DisplayClass2_0`1.<GetMonthlySum>b__0(IGrouping`2 g)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
at UserQuery.Main()

```
private IEnumerable<Tubo<TKey>> GetMonthlySum<TKey>(IEnumerable<IGrouping<TKey,ProductValue>> query)
{
return query.Select(g => new Tubo<TKey>
{
Group = g,
Required = g.AsQueryable().Where( pv => pv.Product != null).Count()
});
}

public class Tubo<TKey>
{
public IGrouping<TKey, ProductValue> Group { get; set; }
public int Required { get; set; }
}
```
Comments: Looks like you need to enable MARS by adding `MultipleActiveResultSets=True;` to your connection string.

Created Unassigned: Make KeyAttribute to have an IsRowguidcol property and the fluent API's [2838]

$
0
0
In [Microsoft's guidance](http://blogs.msdn.com/b/repltalk/archive/2010/03/03/all-about-identity-range-management.aspx) it amongst others reads:

> Alternatively, you could avoid Identity Range Management problems altogether by using GUIDs as table Primary Key. This may reduce storage requirements as Merge Replication automatically adds Rowguid when table is published. If one already exists and is flagged as ROWGUIDCOL property in table design, Merge will use that column instead of adding a new Rowguid column.

I understand from [our discussion](https://entityframework.codeplex.com/workitem/2796) that you don't want to mechanically add the ROWGUIDCOL property in the generated code as you wrote:
> this is not something that we want to generate in all cases since it seems to be designed for a very narrow use case

I would like to suggest, that the KeyAttribute should have a property IsRowguidcol which can be either "No", your default, or "Auto":, for the behavior I suggested in [our discussion](https://entityframework.codeplex.com/workitem/2796) like this:
```
public class Blog
{
[Key(IsRowguidcol = Auto)]
public Guid PrimaryTrackingKey { get; set; }

...
}

```

The fluent Api should offer the same kind of possibility.

I would consider this approach to be analogous to the IndexAttribute having an IsClustered property and therefore in line with your design preferences.


Best regards,

Henrik Dahl

Edited Unassigned: Make KeyAttribute to have an IsRowguidcol property and the fluent API's to have an equivalent possibility [2838]

$
0
0
In [Microsoft's guidance](http://blogs.msdn.com/b/repltalk/archive/2010/03/03/all-about-identity-range-management.aspx) it amongst others reads:

> Alternatively, you could avoid Identity Range Management problems altogether by using GUIDs as table Primary Key. This may reduce storage requirements as Merge Replication automatically adds Rowguid when table is published. If one already exists and is flagged as ROWGUIDCOL property in table design, Merge will use that column instead of adding a new Rowguid column.

I understand from [our discussion](https://entityframework.codeplex.com/workitem/2796) that you don't want to mechanically add the ROWGUIDCOL property in the generated code as you wrote:
> this is not something that we want to generate in all cases since it seems to be designed for a very narrow use case

I would like to suggest, that the KeyAttribute should have a property IsRowguidcol which can be either "No", your default, or "Auto":, for the behavior I suggested in [our discussion](https://entityframework.codeplex.com/workitem/2796) like this:
```
public class Blog
{
[Key(IsRowguidcol = Auto)]
public Guid PrimaryTrackingKey { get; set; }

...
}

```

The fluent Api should offer the same kind of possibility.

I would consider this approach to be analogous to the IndexAttribute having an IsClustered property and therefore in line with your design preferences.


Best regards,

Henrik Dahl

Edited Unassigned: Make KeyAttribute to have an IsRowguidcol property and the fluent Api to have an equivalent possibility [2838]

$
0
0
In [Microsoft's guidance](http://blogs.msdn.com/b/repltalk/archive/2010/03/03/all-about-identity-range-management.aspx) it amongst others reads:

> Alternatively, you could avoid Identity Range Management problems altogether by using GUIDs as table Primary Key. This may reduce storage requirements as Merge Replication automatically adds Rowguid when table is published. If one already exists and is flagged as ROWGUIDCOL property in table design, Merge will use that column instead of adding a new Rowguid column.

I understand from [our discussion](https://entityframework.codeplex.com/workitem/2796) that you don't want to mechanically add the ROWGUIDCOL property in the generated code as you wrote:
> this is not something that we want to generate in all cases since it seems to be designed for a very narrow use case

I would like to suggest, that the KeyAttribute should have a property IsRowguidcol which can be either "No", your default, or "Auto":, for the behavior I suggested in [our discussion](https://entityframework.codeplex.com/workitem/2796) like this:
```
public class Blog
{
[Key(IsRowguidcol = Auto)]
public Guid PrimaryTrackingKey { get; set; }

...
}

```

The fluent Api should offer the same kind of possibility.

I would consider this approach to be analogous to the IndexAttribute having an IsClustered property and therefore in line with your design preferences.


Best regards,

Henrik Dahl

Created Unassigned: Make the KeyAttibute to have an IsClustered attibute [2839]

$
0
0
It is nice, that the IndexAttribute has the IsClustered property so you can define an index to be clustered.

The generated SQL using the migration feature does not define the primary key to have a clustered index, so everything could look fine, as there obviously can be only one clustered index.

The problem however is, that SQL Server by default defines the index for the primary key to be clustered if it's not explicitly marked nonclustered. As a consequence you are being prevented from making any index of your own to be clustered.

Thefore I would suggest to add an IsClustered property to the KeyAttribute which should work exactly like the IsClustered property of the IndexAttribute like:
```
public class Blog
{
[Key(IsClustered = false)]
public int PrimaryTrackingKey { get; set; }
public string Title { get; set; }
[Index(IsClustered = true)]
public string BloggerName { get; set;}
public virtual ICollection<Post> Posts { get; set; }
}

```

The fluent Api should obviously offer an equivalent expressional power.


Best regards,

Henrik Dahl

Edited Unassigned: Make the KeyAttibute to have an IsClustered property [2839]

$
0
0
It is nice, that the IndexAttribute has the IsClustered property so you can define an index to be clustered.

The generated SQL using the migration feature does not define the primary key to have a clustered index, so everything could look fine, as there obviously can be only one clustered index.

The problem however is, that SQL Server by default defines the index for the primary key to be clustered if it's not explicitly marked nonclustered. As a consequence you are being prevented from making any index of your own to be clustered.

Thefore I would suggest to add an IsClustered property to the KeyAttribute which should work exactly like the IsClustered property of the IndexAttribute like:
```
public class Blog
{
[Key(IsClustered = false)]
public int PrimaryTrackingKey { get; set; }
public string Title { get; set; }
[Index(IsClustered = true)]
public string BloggerName { get; set;}
public virtual ICollection<Post> Posts { get; set; }
}

```

The fluent Api should obviously offer an equivalent expressional power.


Best regards,

Henrik Dahl

Viewing all 10318 articles
Browse latest View live




Latest Images