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

Commented Unassigned: Global filtering with 4 base classes and about 150 entities [2854]

0
0
Hello,
I am totally losing faith in EF after getting absolutely nowhere with global filters and getting help over the internet.

I have a 4 base classes for my entities:
System Entity
Business Entity - inherists from system entity
Versioned Entity inherits from business
Published Entity inherits from business

I have a property bool Archived on the system and I want to always retrieve those with Archive=false
I also have a PublishLevel on the Published entity and I want to retrieve specific versions.

I created an interface that holds all the common fields across the entities and implemented the members on system entity. Some of the fields had to be marked as notmapped in order to avoid looking for publish level on entities that aren't supposed to have them.

I wrote to extension methods to IQueryable<T> where T is IEntity (my interface), class
The first one filters archives, the other one filters versioned entities using the publishlevel property depending on your role.

To keep the code clean and avoid 150+ retrieve methods one for each entity, I am attempting this using DbContext.Set<T>.TrimArchives().TrimVersions()

All that works great except I am no longer able to query by any other property other than those defined in the interface. That makes me a sad panda.
Comments: Hey, This is unfortunately a limitation of how EF6 (and earlier versions) reasons about types. It's not exactly simple... but you can workaround this by dynamically building expressions to pass to the LINQ query. Below is an example of the `TrimArchives()` method you mentioned. ~Rowan ``` using System; using System.Data.Entity; using System.Linq; using System.Linq.Expressions; namespace ConsoleApplication13 { class Program { static void Main(string[] args) { using (var db = new MyContext()) { if (!db.Customers.Any()) { db.Customers.Add(new Customer { FirstName = "Jane", LastName = "Doe", IsArchived = false }); db.Customers.Add(new Customer { FirstName = "John", LastName = "Doe", IsArchived = true }); db.SaveChanges(); } var query = db.Customers .TrimArchives() .OrderBy(c => c.FirstName) .ToList(); foreach (var item in query) { Console.WriteLine(item.FirstName); } } } } public static class Extensions { public static IQueryable<TEntity> TrimArchives<TEntity>(this IQueryable<TEntity> query) where TEntity : IEntity { var param = Expression.Parameter(typeof(TEntity), "e"); var body = Expression.MakeBinary( ExpressionType.Equal, Expression.Property(param, "IsArchived"), Expression.Constant(false)); return query.Where(Expression.Lambda<Func<TEntity, bool>>(body, param)); } } public class MyContext : DbContext { public DbSet<Customer> Customers { get; set; } } public class Customer : BaseEntity { public string FirstName { get; set; } public string LastName { get; set; } } public class BaseEntity : IEntity { public int Id { get; set; } public bool IsArchived { get; set; } } public interface IEntity { bool IsArchived { get; } } } ```

Commented Unassigned: Global filtering with 4 base classes and about 150 entities [2854]

0
0
Hello,
I am totally losing faith in EF after getting absolutely nowhere with global filters and getting help over the internet.

I have a 4 base classes for my entities:
System Entity
Business Entity - inherists from system entity
Versioned Entity inherits from business
Published Entity inherits from business

I have a property bool Archived on the system and I want to always retrieve those with Archive=false
I also have a PublishLevel on the Published entity and I want to retrieve specific versions.

I created an interface that holds all the common fields across the entities and implemented the members on system entity. Some of the fields had to be marked as notmapped in order to avoid looking for publish level on entities that aren't supposed to have them.

I wrote to extension methods to IQueryable<T> where T is IEntity (my interface), class
The first one filters archives, the other one filters versioned entities using the publishlevel property depending on your role.

To keep the code clean and avoid 150+ retrieve methods one for each entity, I am attempting this using DbContext.Set<T>.TrimArchives().TrimVersions()

All that works great except I am no longer able to query by any other property other than those defined in the interface. That makes me a sad panda.
Comments: BTW I verified that in EF7 this limitation is gone. The following implementation of TrimArchives works on EF7 RC1. ``` public static IQueryable<TEntity> TrimArchives<TEntity>(this IQueryable<TEntity> query) where TEntity : IEntity { return query.Where(e => !e.IsArchived); } ```

Commented Unassigned: Global filtering with 4 base classes and about 150 entities [2854]

0
0
Hello,
I am totally losing faith in EF after getting absolutely nowhere with global filters and getting help over the internet.

I have a 4 base classes for my entities:
System Entity
Business Entity - inherists from system entity
Versioned Entity inherits from business
Published Entity inherits from business

I have a property bool Archived on the system and I want to always retrieve those with Archive=false
I also have a PublishLevel on the Published entity and I want to retrieve specific versions.

I created an interface that holds all the common fields across the entities and implemented the members on system entity. Some of the fields had to be marked as notmapped in order to avoid looking for publish level on entities that aren't supposed to have them.

I wrote to extension methods to IQueryable<T> where T is IEntity (my interface), class
The first one filters archives, the other one filters versioned entities using the publishlevel property depending on your role.

To keep the code clean and avoid 150+ retrieve methods one for each entity, I am attempting this using DbContext.Set<T>.TrimArchives().TrimVersions()

All that works great except I am no longer able to query by any other property other than those defined in the interface. That makes me a sad panda.
Comments: Hi Rob, Thanks for coming back to me. My project goes live in April and so does EF7 so I doubt I can use it. Fortunately I found a nuget package called EntityFramework.DynamicFilters and will be giving it a go. Surely EF6.x has some benefits over other ORM solutions for rapid development but at a large scale I am inclined to say that EF could use some work. I am also having nightmares with the fluent mapping of 150+ and increasing by the month entities). Annotations feel much faster

Created Unassigned: Disappearing double-child entities after commit [2857]

0
0
I have following structure:
```c#
class Parent
{
public int Id { get; set; }
public virtual ICollection<Child> Children { get; set; }
}
class Child
{
public int Id { get; set; }
public int ParentId { get; set; }
public virtual Parent Parent { get; set; }
public virtual ICollection<SubChild> SubChildren { get; set; }
}
class SubChild
{
public int Id { get; set; }
public int ParentId { get; set; }
public int ChildId { get; set; }
public virtual Child Child { get; set; }
}
```
and following fluent configuration:
```c#
public class ParentMap : EntityTypeConfiguration<Parent>
{
public ParentMap()
{
HasKey(t => t.Id)
.Property(t => t.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
}
}

public class ChildMap : EntityTypeConfiguration<Child>
{
public ChildMap()
{
HasKey(t => new { t.Id, t.ParentId }) // to make ensure that child entity go away after removing from nested collection in the parent entity. it works where there is relationship between parent and child entities only. take a look next
.Property(t => t.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

HasRequired(t => t.Parent)
.WithMany(c => c.Children)
.HasForeignKey(c => c.ParentId)
.WillCascadeOnDelete();
}
}

public class SubChildMap : EntityTypeConfiguration<SubChild>
{
public SubChildMap()
{
HasKey(t => new { t.Id, t.ChildId, t.ParentId }) // to make ensure that values are removable when child (parent for this) is being removed from Child collection in a Parent entity
.Property(t => t.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

HasRequired(t => t.Child)
.WithMany(t => t.SubChildren)
.HasForeignKey(d => new {d.ChildId, d.ParentId})
.WillCascadeOnDelete();
}
}
```

With the configuration I get unexpected behavior. Here is working code:
```c#
var parent = new Parent() {
Children = new List<Children>() {new Child {SubChildren=new List<SubChild>() {new SubChild(){}}}};
};
using (var ctx = new K3Context())
{
ctx.Set<Parent>().Add(parent);
ctx.SaveChanges();

Assert.AreEqual(1, parent.Children.SelectMany(c => c.SubChildren).Count()); // everithing is ok for new instance
}
```
But when I try to store exist entity and try to mutate it I face to weird behavior:
```c#
var parent = new Parent() {
Children = new List<Children>() {new Child {SubChildren=new List<SubChild>() {new SubChild(){}}}};
};
using (var ctx = new K3Context())
{
var entity = ctx.Set<Parent>().Where(p=>p.Id=knownId).FirstOrDefault();
entity .Children.Remove(entity .Children.Last());
entity .Children.Add(new Child () {SubChildren = new List<SubChild>() {new SubChild()}});
ctx.SaveChanges();

Assert.AreEqual(1, parent.Children.SelectMany(c => c.SubChildren).Count()); // it fails because there is nothing and nested collection
}
```
What is strange that is data appears in the DB but it disappears after committing changes.

If I change configuration to use single key (not assembled from several id fields) everything is ok again but I'm obliged to remove Child from context permanently (I don't want to do it therefore I made the configuration because context is hidden behind repository pattern without any direct access to EF context).

If I retrieve data from DB I get correct SubChildren collection with entities I put to save bit they are behind proxy.

Reviewed: EF 6.1.3 (十一月 24, 2015)

0
0
Rated 5 Stars (out of 5) - view entity framework source code

Commented Unassigned: Global filtering with 4 base classes and about 150 entities [2854]

0
0
Hello,
I am totally losing faith in EF after getting absolutely nowhere with global filters and getting help over the internet.

I have a 4 base classes for my entities:
System Entity
Business Entity - inherists from system entity
Versioned Entity inherits from business
Published Entity inherits from business

I have a property bool Archived on the system and I want to always retrieve those with Archive=false
I also have a PublishLevel on the Published entity and I want to retrieve specific versions.

I created an interface that holds all the common fields across the entities and implemented the members on system entity. Some of the fields had to be marked as notmapped in order to avoid looking for publish level on entities that aren't supposed to have them.

I wrote to extension methods to IQueryable<T> where T is IEntity (my interface), class
The first one filters archives, the other one filters versioned entities using the publishlevel property depending on your role.

To keep the code clean and avoid 150+ retrieve methods one for each entity, I am attempting this using DbContext.Set<T>.TrimArchives().TrimVersions()

All that works great except I am no longer able to query by any other property other than those defined in the interface. That makes me a sad panda.
Comments: > I am also having nightmares with the fluent mapping of 150+ and increasing by the month entities). Annotations feel much faster Annotations are a perfectly valid form of configuration (in EF6 and EF7).

Commented Feature: Provide better support for working with disconnected entities [864]

0
0
This item is to track adding better support for change tracking with graphs of disconnected entities. For more information see this discussion:

"Merge Disconnected Object Graph"
http://entityframework.codeplex.com/discussions/432661

And this user voice item:

"Merge method: automatic synchronization of relationships on a disconnected entity"
http://data.uservoice.com/forums/72025-entity-framework-feature-suggestions/suggestions/1069431-merge-method-automatic-synchronization-of-relation

Comments: This is a joke - why are we even using ORM if we are to write its infrastructural code ourselves.

New Post: 1876 [UpForGrabs] [Performance] Reduce start up time by loading finished Code First models from a persistent cache

0
0
I noticed that extended metadata properties without namespaces in their identifiers are not serialized (See WriteExtendedProperties in EdmXmlSchemaWriter).

For me, this means that TableName is not stored in the edmx file, which causes a crash in one of our applications when it tries to retrieve the table name for an entity using code similar to the code in this blog post.

I am not super familiar with EF or its source code.. Is it intentional that these properties are not stored?

New Post: 1876 [UpForGrabs] [Performance] Reduce start up time by loading finished Code First models from a persistent cache

0
0
@blorgbeard It is most likely just a limitation of the serialization code that probably wouldn't matter in other scenarios.

Created Unassigned: EF running UPDATE twice with the same data, and data hasn't changed either [2858]

0
0
Whenever i SaveChanges() when I have loaded entities for a certain class, and eventhough I haven't changed *anything*, UPDATEs are executed. And they are even executed twice with identical data. E.g.:

UPDATE [dbo].[UserCustomerPortfoliosPortfolios]
SET [SortOrder] = @0
WHERE ((([Username] = @1) AND ([CustomerId] = @2)) AND ([PortfolioId] = @3))

-- @0: '2' (Type = Int32)
-- @1: 'emmu' (Type = String, Size = 128)
-- @2: '1' (Type = Int32)
-- @3: '121' (Type = Int32)

-- Executing asynchronously at 12/2/2015 3:28:15 PM +01:00

UPDATE [dbo].[UserCustomerPortfoliosPortfolios]
SET [SortOrder] = @0
WHERE ((([Username] = @1) AND ([CustomerId] = @2)) AND ([PortfolioId] = @3))

-- @0: '2' (Type = Int32)
-- @1: 'emmu' (Type = String, Size = 128)
-- @2: '1' (Type = Int32)
-- @3: '121' (Type = Int32)

-- Executing asynchronously at 12/2/2015 3:28:15 PM +01:00

-- Completed in 11 ms with result: 1

The class in question is called 'UserCustomerPortfoliosPortfolio'. Here are some models:

public class UserCustomerPortfoliosPortfolio
{
public virtual User User { get; set; }
public virtual string Username { get; set; }
public virtual Customer Customer { get; set; }
public virtual int CustomerId { get; set; }
public virtual UserCustomerPortfolios UserCustomerPortfolios { get; set; }
public virtual Portfolio Portfolio { get; set; }
public virtual int PortfolioId { get; set; }
public virtual int SortOrder { get; set; }
}

public class User
{
public virtual string Username { get; set; }
public virtual string Email { get; set; }
public virtual ICollection<UserCustomerPortfolios> Customers { get; set; }
public virtual string UICultureName { get; set; }
public virtual ICollection<Page> Pages { get; set; }
public virtual ICollection<Module> Modules { get; set; }
public virtual DateTimeOffset LastLoginTime { get; set; }
public virtual ICollection<UserLogEntry> LogEntries { get; set; }
}

public class Customer
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual ICollection<Portfolio> Portfolios { get; set; }
public virtual int SortOrder { get; set; }
}

public class Portfolio
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual Customer Customer { get; set; }
public virtual int SortOrder { get; set; }
}

public class UserCustomerPortfolios
{
public virtual User User { get; set; }
public virtual string Username { get; set; }
public virtual Customer Customer { get; set; }
public virtual int CustomerId { get; set; }
public virtual ICollection<UserCustomerPortfoliosPortfolio> Portfolios { get; set; }
public virtual int SortOrder { get; set; }
}

Fluid configuration:

modelBuilder.Entity<User>().HasKey(u => u.Username);
modelBuilder.Entity<User>().Property(p => p.Email).IsRequired();
modelBuilder.Entity<User>().HasMany(u => u.Pages).WithMany();
modelBuilder.Entity<User>().HasMany(u => u.Modules).WithMany();
modelBuilder.Entity<User>().HasMany(u => u.LogEntries);

modelBuilder.Entity<Customer>().HasMany(c => c.Portfolios).WithOptional(p => p.Customer);

modelBuilder.Entity<Portfolio>().Property(p => p.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

modelBuilder.Entity<UserCustomerPortfolios>().HasKey(u => new { u.Username, u.CustomerId });
modelBuilder.Entity<UserCustomerPortfolios>().HasRequired(u => u.User).WithMany(u => u.Customers).HasForeignKey(u => u.Username);
modelBuilder.Entity<UserCustomerPortfolios>().HasRequired(c => c.Customer).WithMany().HasForeignKey(u => u.CustomerId);

modelBuilder.Entity<UserCustomerPortfoliosPortfolio>().HasKey(p => new { p.Username, p.CustomerId, p.PortfolioId });
modelBuilder.Entity<UserCustomerPortfoliosPortfolio>().HasRequired(p => p.User).WithMany().HasForeignKey(p => p.Username);
modelBuilder.Entity<UserCustomerPortfoliosPortfolio>().HasRequired(p => p.Customer).WithMany().HasForeignKey(p => p.CustomerId);
modelBuilder.Entity<UserCustomerPortfoliosPortfolio>().HasRequired(p => p.UserCustomerPortfolios).WithMany(p => p.Portfolios).HasForeignKey(p => new { p.Username, p.CustomerId }).WillCascadeOnDelete(false);
modelBuilder.Entity<UserCustomerPortfoliosPortfolio>().HasRequired(p => p.Portfolio).WithMany().HasForeignKey(p => p.PortfolioId);


modelBuilder.Entity<Page>().HasKey(p => p.Name);
modelBuilder.Entity<Page>().HasMany(p => p.Modules).WithMany();

modelBuilder.Entity<Module>().HasKey(m => m.Name);

modelBuilder.Entity<Folder>().HasMany(f => f.Folders).WithOptional(f => f.Parent);
modelBuilder.Entity<Folder>().HasMany(f => f.Files).WithOptional(f => f.Parent);

(I left part of the model out as I don't believe it is relevant)
(Also, SaveChanges is wrapped within a BeginTransaction() if that matters)


Also, related to the above model (probably UserCustomerPortfoliosPortfolio):

I sometimes get a NullReferenceException when I SaveChanges().
If I add some more SaveChanges() before the relevant line, it works.

Stack trace:

[NullReferenceException: Object reference not set to an instance of an object.]
System.Data.Entity.Core.Objects.EntityEntry.EntityMemberChanged(String entityMemberName, Object complexObject, String complexObjectMemberName) +1077
System.Data.Entity.Core.Objects.EntityEntry.EntityMemberChanged(String entityMemberName) +39
System.Data.Entity.Core.Objects.ObjectStateEntry.System.Data.Entity.Core.Objects.DataClasses.IEntityChangeTracker.EntityMemberChanged(String entityMemberName) +12
System.Data.Entity.Core.Objects.Internal.SnapshotChangeTrackingStrategy.SetCurrentValue(EntityEntry entry, StateManagerMemberMetadata member, Int32 ordinal, Object target, Object value) +81
System.Data.Entity.Core.Objects.Internal.EntityWrapper`1.SetCurrentValue(EntityEntry entry, StateManagerMemberMetadata member, Int32 ordinal, Object target, Object value) +25
System.Data.Entity.Core.Objects.EntityEntry.SetCurrentEntityValue(StateManagerTypeMetadata metadata, Int32 ordinal, Object userObject, Object newValue) +164
System.Data.Entity.Core.Objects.ObjectStateEntryDbUpdatableDataRecord.SetRecordValue(Int32 ordinal, Object value) +65
System.Data.Entity.Core.Mapping.Update.Internal.PropagatorResult.SetServerGenValue(Object value) +147
System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.BackPropagateServerGen(List`1 generatedValues) +368
System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update() +345
System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<Update>b__2(UpdateTranslator ut) +11
System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update(T noChangesResult, Func`2 updateFunction) +132
System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update() +106
System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__35() +13
System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) +288
System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction) +157
System.Data.Entity.Core.Objects.<>c__DisplayClass2a.<SaveChangesInternal>b__27() +25
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1 operation) +162
System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction) +221
System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options) +11
System.Data.Entity.Internal.InternalContext.SaveChanges() +113
System.Data.Entity.Internal.LazyInternalContext.SaveChanges() +27
System.Data.Entity.DbContext.SaveChanges() +22
Grieg.Web.Mvc.GriegDatabaseInitializer.Seed(GriegDbContext context) in D:\Grieg\Grieg.Web.Mvc\GriegDatabaseInitializer.cs:109
System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context) +172
System.Data.Entity.Internal.<>c__DisplayClassf`1.<CreateInitializationAction>b__e() +76
System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +60
System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +395
System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c) +11
System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) +110
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) +214
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() +97
System.Data.Entity.Internal.LazyInternalContext.get_ObjectContext() +26
System.Data.Entity.Internal.InternalContext.ExecuteSqlQuery(String sql, Nullable`1 streaming, Object[] parameters) +109
System.Data.Entity.Internal.InternalContext.ExecuteSqlQueryAsIEnumerator(String sql, Nullable`1 streaming, Object[] parameters) +68
System.Data.Entity.Internal.InternalContext.ExecuteSqlQuery(Type elementType, String sql, Nullable`1 streaming, Object[] parameters) +190
System.Data.Entity.Internal.InternalSqlNonSetQuery.GetEnumerator() +41
System.Data.Entity.Infrastructure.DbRawSqlQuery`1.GetEnumerator() +31
Grieg.Web.Mvc.GriegDbContext.Initialize() in D:\Grieg\Grieg.Web.Mvc\GriegDbContext.cs:84
Grieg.Web.Mvc.Startup.Configuration(IAppBuilder app) in D:\Grieg\Grieg.Web.Mvc\Startup.cs:36

Let me know if more info is needed.

Kind regards,
Emil Müller

Edited Unassigned: EF running UPDATE twice with the same data for the same row, and data hasn't changed either [2858]

0
0
Whenever i SaveChanges() when I have loaded entities for a certain class, and eventhough I haven't changed *anything*, UPDATEs are executed. And they are even executed twice with identical data. E.g.:

UPDATE [dbo].[UserCustomerPortfoliosPortfolios]
SET [SortOrder] = @0
WHERE ((([Username] = @1) AND ([CustomerId] = @2)) AND ([PortfolioId] = @3))

-- @0: '2' (Type = Int32)
-- @1: 'emmu' (Type = String, Size = 128)
-- @2: '1' (Type = Int32)
-- @3: '121' (Type = Int32)

-- Executing asynchronously at 12/2/2015 3:28:15 PM +01:00

UPDATE [dbo].[UserCustomerPortfoliosPortfolios]
SET [SortOrder] = @0
WHERE ((([Username] = @1) AND ([CustomerId] = @2)) AND ([PortfolioId] = @3))

-- @0: '2' (Type = Int32)
-- @1: 'emmu' (Type = String, Size = 128)
-- @2: '1' (Type = Int32)
-- @3: '121' (Type = Int32)

-- Executing asynchronously at 12/2/2015 3:28:15 PM +01:00

-- Completed in 11 ms with result: 1

The class in question is called 'UserCustomerPortfoliosPortfolio'. Here are some models:

public class UserCustomerPortfoliosPortfolio
{
public virtual User User { get; set; }
public virtual string Username { get; set; }
public virtual Customer Customer { get; set; }
public virtual int CustomerId { get; set; }
public virtual UserCustomerPortfolios UserCustomerPortfolios { get; set; }
public virtual Portfolio Portfolio { get; set; }
public virtual int PortfolioId { get; set; }
public virtual int SortOrder { get; set; }
}

public class User
{
public virtual string Username { get; set; }
public virtual string Email { get; set; }
public virtual ICollection<UserCustomerPortfolios> Customers { get; set; }
public virtual string UICultureName { get; set; }
public virtual ICollection<Page> Pages { get; set; }
public virtual ICollection<Module> Modules { get; set; }
public virtual DateTimeOffset LastLoginTime { get; set; }
public virtual ICollection<UserLogEntry> LogEntries { get; set; }
}

public class Customer
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual ICollection<Portfolio> Portfolios { get; set; }
public virtual int SortOrder { get; set; }
}

public class Portfolio
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual Customer Customer { get; set; }
public virtual int SortOrder { get; set; }
}

public class UserCustomerPortfolios
{
public virtual User User { get; set; }
public virtual string Username { get; set; }
public virtual Customer Customer { get; set; }
public virtual int CustomerId { get; set; }
public virtual ICollection<UserCustomerPortfoliosPortfolio> Portfolios { get; set; }
public virtual int SortOrder { get; set; }
}

Fluid configuration:

modelBuilder.Entity<User>().HasKey(u => u.Username);
modelBuilder.Entity<User>().Property(p => p.Email).IsRequired();
modelBuilder.Entity<User>().HasMany(u => u.Pages).WithMany();
modelBuilder.Entity<User>().HasMany(u => u.Modules).WithMany();
modelBuilder.Entity<User>().HasMany(u => u.LogEntries);

modelBuilder.Entity<Customer>().HasMany(c => c.Portfolios).WithOptional(p => p.Customer);

modelBuilder.Entity<Portfolio>().Property(p => p.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

modelBuilder.Entity<UserCustomerPortfolios>().HasKey(u => new { u.Username, u.CustomerId });
modelBuilder.Entity<UserCustomerPortfolios>().HasRequired(u => u.User).WithMany(u => u.Customers).HasForeignKey(u => u.Username);
modelBuilder.Entity<UserCustomerPortfolios>().HasRequired(c => c.Customer).WithMany().HasForeignKey(u => u.CustomerId);

modelBuilder.Entity<UserCustomerPortfoliosPortfolio>().HasKey(p => new { p.Username, p.CustomerId, p.PortfolioId });
modelBuilder.Entity<UserCustomerPortfoliosPortfolio>().HasRequired(p => p.User).WithMany().HasForeignKey(p => p.Username);
modelBuilder.Entity<UserCustomerPortfoliosPortfolio>().HasRequired(p => p.Customer).WithMany().HasForeignKey(p => p.CustomerId);
modelBuilder.Entity<UserCustomerPortfoliosPortfolio>().HasRequired(p => p.UserCustomerPortfolios).WithMany(p => p.Portfolios).HasForeignKey(p => new { p.Username, p.CustomerId }).WillCascadeOnDelete(false);
modelBuilder.Entity<UserCustomerPortfoliosPortfolio>().HasRequired(p => p.Portfolio).WithMany().HasForeignKey(p => p.PortfolioId);


modelBuilder.Entity<Page>().HasKey(p => p.Name);
modelBuilder.Entity<Page>().HasMany(p => p.Modules).WithMany();

modelBuilder.Entity<Module>().HasKey(m => m.Name);

modelBuilder.Entity<Folder>().HasMany(f => f.Folders).WithOptional(f => f.Parent);
modelBuilder.Entity<Folder>().HasMany(f => f.Files).WithOptional(f => f.Parent);

(I left part of the model out as I don't believe it is relevant)
(Also, SaveChanges is wrapped within a BeginTransaction() if that matters)


Also, related to the above model (probably UserCustomerPortfoliosPortfolio):

I sometimes get a NullReferenceException when I SaveChanges().
If I add some more SaveChanges() before the relevant line, it works.

Stack trace:

[NullReferenceException: Object reference not set to an instance of an object.]
System.Data.Entity.Core.Objects.EntityEntry.EntityMemberChanged(String entityMemberName, Object complexObject, String complexObjectMemberName) +1077
System.Data.Entity.Core.Objects.EntityEntry.EntityMemberChanged(String entityMemberName) +39
System.Data.Entity.Core.Objects.ObjectStateEntry.System.Data.Entity.Core.Objects.DataClasses.IEntityChangeTracker.EntityMemberChanged(String entityMemberName) +12
System.Data.Entity.Core.Objects.Internal.SnapshotChangeTrackingStrategy.SetCurrentValue(EntityEntry entry, StateManagerMemberMetadata member, Int32 ordinal, Object target, Object value) +81
System.Data.Entity.Core.Objects.Internal.EntityWrapper`1.SetCurrentValue(EntityEntry entry, StateManagerMemberMetadata member, Int32 ordinal, Object target, Object value) +25
System.Data.Entity.Core.Objects.EntityEntry.SetCurrentEntityValue(StateManagerTypeMetadata metadata, Int32 ordinal, Object userObject, Object newValue) +164
System.Data.Entity.Core.Objects.ObjectStateEntryDbUpdatableDataRecord.SetRecordValue(Int32 ordinal, Object value) +65
System.Data.Entity.Core.Mapping.Update.Internal.PropagatorResult.SetServerGenValue(Object value) +147
System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.BackPropagateServerGen(List`1 generatedValues) +368
System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update() +345
System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<Update>b__2(UpdateTranslator ut) +11
System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update(T noChangesResult, Func`2 updateFunction) +132
System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update() +106
System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__35() +13
System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) +288
System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction) +157
System.Data.Entity.Core.Objects.<>c__DisplayClass2a.<SaveChangesInternal>b__27() +25
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1 operation) +162
System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction) +221
System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options) +11
System.Data.Entity.Internal.InternalContext.SaveChanges() +113
System.Data.Entity.Internal.LazyInternalContext.SaveChanges() +27
System.Data.Entity.DbContext.SaveChanges() +22
Grieg.Web.Mvc.GriegDatabaseInitializer.Seed(GriegDbContext context) in D:\Grieg\Grieg.Web.Mvc\GriegDatabaseInitializer.cs:109
System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context) +172
System.Data.Entity.Internal.<>c__DisplayClassf`1.<CreateInitializationAction>b__e() +76
System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +60
System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +395
System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c) +11
System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) +110
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) +214
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() +97
System.Data.Entity.Internal.LazyInternalContext.get_ObjectContext() +26
System.Data.Entity.Internal.InternalContext.ExecuteSqlQuery(String sql, Nullable`1 streaming, Object[] parameters) +109
System.Data.Entity.Internal.InternalContext.ExecuteSqlQueryAsIEnumerator(String sql, Nullable`1 streaming, Object[] parameters) +68
System.Data.Entity.Internal.InternalContext.ExecuteSqlQuery(Type elementType, String sql, Nullable`1 streaming, Object[] parameters) +190
System.Data.Entity.Internal.InternalSqlNonSetQuery.GetEnumerator() +41
System.Data.Entity.Infrastructure.DbRawSqlQuery`1.GetEnumerator() +31
Grieg.Web.Mvc.GriegDbContext.Initialize() in D:\Grieg\Grieg.Web.Mvc\GriegDbContext.cs:84
Grieg.Web.Mvc.Startup.Configuration(IAppBuilder app) in D:\Grieg\Grieg.Web.Mvc\Startup.cs:36

Let me know if more info is needed.

Kind regards,
Emil Müller

Commented Unassigned: EF running UPDATE twice with the same data for the same row, and data hasn't changed either [2858]

0
0
Whenever i SaveChanges() when I have loaded entities for a certain class, and eventhough I haven't changed *anything*, UPDATEs are executed. And they are even executed twice with identical data. E.g.:

UPDATE [dbo].[UserCustomerPortfoliosPortfolios]
SET [SortOrder] = @0
WHERE ((([Username] = @1) AND ([CustomerId] = @2)) AND ([PortfolioId] = @3))

-- @0: '2' (Type = Int32)
-- @1: 'emmu' (Type = String, Size = 128)
-- @2: '1' (Type = Int32)
-- @3: '121' (Type = Int32)

-- Executing asynchronously at 12/2/2015 3:28:15 PM +01:00

UPDATE [dbo].[UserCustomerPortfoliosPortfolios]
SET [SortOrder] = @0
WHERE ((([Username] = @1) AND ([CustomerId] = @2)) AND ([PortfolioId] = @3))

-- @0: '2' (Type = Int32)
-- @1: 'emmu' (Type = String, Size = 128)
-- @2: '1' (Type = Int32)
-- @3: '121' (Type = Int32)

-- Executing asynchronously at 12/2/2015 3:28:15 PM +01:00

-- Completed in 11 ms with result: 1

The class in question is called 'UserCustomerPortfoliosPortfolio'. Here are some models:

public class UserCustomerPortfoliosPortfolio
{
public virtual User User { get; set; }
public virtual string Username { get; set; }
public virtual Customer Customer { get; set; }
public virtual int CustomerId { get; set; }
public virtual UserCustomerPortfolios UserCustomerPortfolios { get; set; }
public virtual Portfolio Portfolio { get; set; }
public virtual int PortfolioId { get; set; }
public virtual int SortOrder { get; set; }
}

public class User
{
public virtual string Username { get; set; }
public virtual string Email { get; set; }
public virtual ICollection<UserCustomerPortfolios> Customers { get; set; }
public virtual string UICultureName { get; set; }
public virtual ICollection<Page> Pages { get; set; }
public virtual ICollection<Module> Modules { get; set; }
public virtual DateTimeOffset LastLoginTime { get; set; }
public virtual ICollection<UserLogEntry> LogEntries { get; set; }
}

public class Customer
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual ICollection<Portfolio> Portfolios { get; set; }
public virtual int SortOrder { get; set; }
}

public class Portfolio
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual Customer Customer { get; set; }
public virtual int SortOrder { get; set; }
}

public class UserCustomerPortfolios
{
public virtual User User { get; set; }
public virtual string Username { get; set; }
public virtual Customer Customer { get; set; }
public virtual int CustomerId { get; set; }
public virtual ICollection<UserCustomerPortfoliosPortfolio> Portfolios { get; set; }
public virtual int SortOrder { get; set; }
}

Fluid configuration:

modelBuilder.Entity<User>().HasKey(u => u.Username);
modelBuilder.Entity<User>().Property(p => p.Email).IsRequired();
modelBuilder.Entity<User>().HasMany(u => u.Pages).WithMany();
modelBuilder.Entity<User>().HasMany(u => u.Modules).WithMany();
modelBuilder.Entity<User>().HasMany(u => u.LogEntries);

modelBuilder.Entity<Customer>().HasMany(c => c.Portfolios).WithOptional(p => p.Customer);

modelBuilder.Entity<Portfolio>().Property(p => p.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

modelBuilder.Entity<UserCustomerPortfolios>().HasKey(u => new { u.Username, u.CustomerId });
modelBuilder.Entity<UserCustomerPortfolios>().HasRequired(u => u.User).WithMany(u => u.Customers).HasForeignKey(u => u.Username);
modelBuilder.Entity<UserCustomerPortfolios>().HasRequired(c => c.Customer).WithMany().HasForeignKey(u => u.CustomerId);

modelBuilder.Entity<UserCustomerPortfoliosPortfolio>().HasKey(p => new { p.Username, p.CustomerId, p.PortfolioId });
modelBuilder.Entity<UserCustomerPortfoliosPortfolio>().HasRequired(p => p.User).WithMany().HasForeignKey(p => p.Username);
modelBuilder.Entity<UserCustomerPortfoliosPortfolio>().HasRequired(p => p.Customer).WithMany().HasForeignKey(p => p.CustomerId);
modelBuilder.Entity<UserCustomerPortfoliosPortfolio>().HasRequired(p => p.UserCustomerPortfolios).WithMany(p => p.Portfolios).HasForeignKey(p => new { p.Username, p.CustomerId }).WillCascadeOnDelete(false);
modelBuilder.Entity<UserCustomerPortfoliosPortfolio>().HasRequired(p => p.Portfolio).WithMany().HasForeignKey(p => p.PortfolioId);


modelBuilder.Entity<Page>().HasKey(p => p.Name);
modelBuilder.Entity<Page>().HasMany(p => p.Modules).WithMany();

modelBuilder.Entity<Module>().HasKey(m => m.Name);

modelBuilder.Entity<Folder>().HasMany(f => f.Folders).WithOptional(f => f.Parent);
modelBuilder.Entity<Folder>().HasMany(f => f.Files).WithOptional(f => f.Parent);

(I left part of the model out as I don't believe it is relevant)
(Also, SaveChanges is wrapped within a BeginTransaction() if that matters)


Also, related to the above model (probably UserCustomerPortfoliosPortfolio):

I sometimes get a NullReferenceException when I SaveChanges().
If I add some more SaveChanges() before the relevant line, it works.

Stack trace:

[NullReferenceException: Object reference not set to an instance of an object.]
System.Data.Entity.Core.Objects.EntityEntry.EntityMemberChanged(String entityMemberName, Object complexObject, String complexObjectMemberName) +1077
System.Data.Entity.Core.Objects.EntityEntry.EntityMemberChanged(String entityMemberName) +39
System.Data.Entity.Core.Objects.ObjectStateEntry.System.Data.Entity.Core.Objects.DataClasses.IEntityChangeTracker.EntityMemberChanged(String entityMemberName) +12
System.Data.Entity.Core.Objects.Internal.SnapshotChangeTrackingStrategy.SetCurrentValue(EntityEntry entry, StateManagerMemberMetadata member, Int32 ordinal, Object target, Object value) +81
System.Data.Entity.Core.Objects.Internal.EntityWrapper`1.SetCurrentValue(EntityEntry entry, StateManagerMemberMetadata member, Int32 ordinal, Object target, Object value) +25
System.Data.Entity.Core.Objects.EntityEntry.SetCurrentEntityValue(StateManagerTypeMetadata metadata, Int32 ordinal, Object userObject, Object newValue) +164
System.Data.Entity.Core.Objects.ObjectStateEntryDbUpdatableDataRecord.SetRecordValue(Int32 ordinal, Object value) +65
System.Data.Entity.Core.Mapping.Update.Internal.PropagatorResult.SetServerGenValue(Object value) +147
System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.BackPropagateServerGen(List`1 generatedValues) +368
System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update() +345
System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<Update>b__2(UpdateTranslator ut) +11
System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update(T noChangesResult, Func`2 updateFunction) +132
System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update() +106
System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__35() +13
System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) +288
System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction) +157
System.Data.Entity.Core.Objects.<>c__DisplayClass2a.<SaveChangesInternal>b__27() +25
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1 operation) +162
System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction) +221
System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options) +11
System.Data.Entity.Internal.InternalContext.SaveChanges() +113
System.Data.Entity.Internal.LazyInternalContext.SaveChanges() +27
System.Data.Entity.DbContext.SaveChanges() +22
Grieg.Web.Mvc.GriegDatabaseInitializer.Seed(GriegDbContext context) in D:\Grieg\Grieg.Web.Mvc\GriegDatabaseInitializer.cs:109
System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context) +172
System.Data.Entity.Internal.<>c__DisplayClassf`1.<CreateInitializationAction>b__e() +76
System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +60
System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +395
System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c) +11
System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) +110
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) +214
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() +97
System.Data.Entity.Internal.LazyInternalContext.get_ObjectContext() +26
System.Data.Entity.Internal.InternalContext.ExecuteSqlQuery(String sql, Nullable`1 streaming, Object[] parameters) +109
System.Data.Entity.Internal.InternalContext.ExecuteSqlQueryAsIEnumerator(String sql, Nullable`1 streaming, Object[] parameters) +68
System.Data.Entity.Internal.InternalContext.ExecuteSqlQuery(Type elementType, String sql, Nullable`1 streaming, Object[] parameters) +190
System.Data.Entity.Internal.InternalSqlNonSetQuery.GetEnumerator() +41
System.Data.Entity.Infrastructure.DbRawSqlQuery`1.GetEnumerator() +31
Grieg.Web.Mvc.GriegDbContext.Initialize() in D:\Grieg\Grieg.Web.Mvc\GriegDbContext.cs:84
Grieg.Web.Mvc.Startup.Configuration(IAppBuilder app) in D:\Grieg\Grieg.Web.Mvc\Startup.cs:36

Let me know if more info is needed.

Kind regards,
Emil Müller
Comments: Interestingly, I am actively setting UserCustomerPortfoliosPortfolio.SortOrder even if the old value is equal to the new value. And an UPDATE is triggered. If I however, compare the old value against the new, and only if they differ, then I trigger the setter, the problem goes away. So I guess there is something wrong in the setter logic of the virtual property.

Created Unassigned: nullable enum generates cast on sql query [2859]

0
0
Using the following sample class:

public class test
{
public long Id { get; set; }
public string Name { get; set; }
public Status? Status { get; set; }
}

public enum Status : short
{
Active,
StandBy
}

with the following linq query:
var quey = DbSet<test>().Where(d => d.Status == Status.Active);

generates the following where clause on sql query:

WHERE (0 = CAST( [Extent1].[Status] AS int))


This is an old issue that was solved on release 6.1.2, but, with not null columns, when there's a nullable column, the issue is still there.

Thanks






Commented Issue: Enable-Migrations throws confusing exception on Web Site projects [568]

0
0
Repro is to install EF on a Web Site project, create a Code First model, and then run the Enable-Migrations command.

Ideally we could support Web Sites projects but Web Site projects are quite different from regular projects and we would probably need to re-do how we interact with EnvDTE, then test it, stabilize it, etc. We haven't seen significant demand of Web Site support, and I believe we already decided not to fix a previous bug for this.

This bug is then about detecting that we are in a Web Site project and throw a clearer exception.

The exception right now looks like this:

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

Server stack trace:
at EnvDTE.Properties.Item(Object index)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at EnvDTE.Properties.Item(Object index)
at System.Data.Entity.Migrations.Extensions.ProjectExtensions.GetPropertyValue[T](Project project, String propertyName)
at System.Data.Entity.Migrations.MigrationsDomainCommand.GetFacade(String configurationTypeName)
at System.Data.Entity.Migrations.EnableMigrationsCommand.FindContextToEnable(String contextTypeName)
at System.Data.Entity.Migrations.EnableMigrationsCommand.<>c__DisplayClass2.<.ctor>b__0()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
PM>
Comments: Dear RoMiller, can you please share an example/sample of how to put migrations into a class library to Enable-Migrations in Web Site in Webforms.

New Post: EDMX designer can't see my EF6 provider

0
0
we're moving our EF provider for DB2 for i (i.e AS400) to EF6 (our previous version works fine in EF4 up to VS2012)
Added new config classes and service providers, etc but still EDMX wizard VS2013 (+EF Tools) cannot recognize it when we try to add a model (database first).
Debugging the provider, we can reach the connection to be used (we have a VS package to integrate the provider with VS itself and add connections) then we choose an available connection (or create a new one) but the next step fails saying an EF 6 provider is not found.

We have followed the guides, like "Rebuilding EF providers for EF6" but till now no luck.

Is there something to do to deepen the debugging? Can we debug the designer to clarify why it does not try to call our Service providers?

Thanks
Alberto

New Post: EDMX designer can't see my EF6 provider

Created Unassigned: Occasional StackOverflow exception translating simple query [2860]

0
0
We've noticed occasional application crashes on some of our IIS websites. When the crash dumps are analyzed, we see that the issue is a StackOverflow with a very large stack that's exclusively in the EF internals. What's odd is that these queries execute thousands of times each day with no issues; the crashes happen ~once per week. This makes me expect some kind of threading issue within EF where certain rare circumstances cached things relied on by the plan compiler become corrupted, leading to unbounded recursion.

Here's the query and model setup where we see this:

using (var myContext = new MyContext())
{
// this is the problematic query
var permissions = from m in myContext.Set<Module>()
from p in m.ModulePermissions
.Where(p => p.UserId == session.User.UserId)
.DefaultIfEmpty()
select new { m.ModuleId, Permission = p }
)
.ToArray();

...
}

public class Session {
public User User {get; set; }
}

public class User { public int UserId {get; set; } }

public class MyContext : DbContext {

public MyContext()
: base(new SqlConnectionStringBuilder { DataSource = @".\sqlexpress", InitialCatalog = "StackOverflowReproAttempt", IntegratedSecurity = true }.ConnectionString)
{
Database.SetInitializer<MyContext>(new CreateDatabaseIfNotExists<MyContext>());
}

protected override void OnModelCreating(DbModelBuilder builder) {
builder.Entity<Module>().HasMany(m => m.ModulePermissions)
.WithRequired(p => p.Module);

builder.Entity<ModulePermission>().HasRequired(p => p.Module)
.WithMany(m => m.ModulePermissions)
.WillCascadeOnDelete(false);
}
}

[Table("Modules", Schema = "dbo")]
public class Module
{
[Column(Order = 1), Key]
public int ModuleId { get; set; }

public virtual ICollection<ModulePermission> ModulePermissions { get; set; }
}

[Table("ModulePermissions", Schema = "dbo")]
public class ModulePermission
{
[Column(Order = 1), Key]
public int UserId { get; set; }

[Column(Order = 2), Key]
public int ModuleId { get; set; }

public virtual Module Module { get; set; }
}

Unfortunately, due to the extremely transient nature of the issue I have not been able to reproduce. I've tried running this query many thousands of times and on different threads, but with no luck. I feel hopeful though, that armed with this query and the attached stack trace someone with more knowledge of the code can come up with a hypothesis for why this happens.

Another note: this seems to be the same as this issue (https://entityframework.codeplex.com/workitem/2817), which was close but not resolved. I noted that issue has a comment about UseDatabaseNullSemantics. We leave this at the default value (false). We've only ever seen this in production, so I don't want to change the value to true there (potentially causing other issues) just to diagnose this.

Even though the crashes happen only occasionally, they cause real disruption for our users so we are hoping to get this issue resolved.

Reviewed: EF 6.1.3 (十二月 04, 2015)

0
0
Rated 5 Stars (out of 5) - very good. I like it.

New Post: Support SQL Server HierarchyId data type

0
0
Hello,

I have just installed EntityFrameworkWithHierarchyId using Nuget.

I have found no documentation how to use it. Can you provide a link to documentation or examples?

Specifically, I have a "Code First from database" and try to edit an entity class to manually add a HierarchyId property.

The HierarchId type is not found.

I have tried adding "using System.Data.Entity.Hierarchy", but it is no recognized. What am I doing wrong?

I also notice that there is no new reference in my project to anything about "hierarchyid", but NuGet shows that the EnityFramwordWithHierarchyId package is install in this project.

Suggestions how to proceed? Or other info you need?

EDIT: I am using Visual Studio 2015, in case that makes a difference. Target .net is 4.5.

EDIT#2: I think maybe EntityFrameworkWithHierarchyId is a replacement for regular EntityFramework, yes? If so, what are the correct steps to remove EntityFramework and replace with EntityFrameworkWithHierarchyId? (maybe there is no trick to thist, I am already trying things)

EDIT#3: (Solution?) Looks like I was correct in Edit#2... I uninstalled both, and then installed only EntityFrameworkWithHierarchyId, and it now recognizes the HierarchyId type.

Thanks!

p.s. Is this the best way, best place to ask questions?

New Post: Support SQL Server HierarchyId data type

0
0
Hi,

Sorry, there is no documentation. You can use the documentation of the official EntityFramework, this is only a small "extension" (technically it is a fork, and replaces the whole official EF)
Here are some examples:

EntityFrameworkWithHierarchyId is not compatible with the official EntityFramework. Was it also installed? You should add reference to my EntityFramework.dll (public key token=6847f3395fc61b47), not to the official one.


2015-12-07 18:03 GMT+01:00 greylander <[email removed]>:

From: greylander

Hello,

I have just installed EntityFrameworkWithHierarchyId using Nuget.

I have found no documentation how to use it. Can you provide a link to documentation or examples?

Specifically, I have a "Code First from database" and try to edit an entity class to manually add a HierarchyId property.

The HierarchId type is not found.

I have tried adding "using System.Data.Entity.Hierarchy", but it is no recognized. What am I doing wrong?

I also notice that there is no new reference in my project to anything about "hierarchyid", but NuGet shows that the EnityFramwordWithHierarchyId package is install in this project.

Suggestions how to proceed? Or other info you need?

Thanks!

p.s. Is this the best way, best place to ask questions?

Read the full discussion online.

To add a post to this discussion, reply to this email ([email removed])

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


Viewing all 10318 articles
Browse latest View live




Latest Images