entity-framework-core

.NET CORE 2 EF Include

China☆狼群 提交于 2019-12-01 18:08:58
I am using new .net core and EF. I need help with include linq command. I have some 1:N models and if the collection contais some data marked like deleted I do not want to include them. How to do it? var company = await _context.Company .Include(y => y.Administrators) .Include(y => y.CompanyPartTimers) .Include(z => z.WorkPlaces) .Include(z => z.Requirements) .FirstAsync(x => x.Id == id); If I add the condition .Include(z => z.WorkPlaces).Where(x=>x.WorkPlaces.Where(x=>!x.IsDeleted)) It doesn't work. How to write this correctly? Next thing is I have IDeletable Interface and it would be better

Including derived child properties in Entity Framework Core 2.0

断了今生、忘了曾经 提交于 2019-12-01 17:57:31
问题 Using Entity Framework Core 2.0, I am trying to construct a query to include related data for a polymorphic child entity. For example, given the following types: public class ParentEntity { public int Id { get; set; } public IList<ChildEntityBase> Children { get; set; } } public abstract class ChildEntityBase { public int Id { get; set; } } public class ChildEntityA : ChildEntityBase { } public class ChildEntityB : ChildEntityBase { public IList<GrandchildEntity> Children { get; set; } }

Does EF7 (EFCore) support enums?

我只是一个虾纸丫 提交于 2019-12-01 17:43:08
问题 I have problem with EF7 RC1 (EFCore). I am unable to work with enums in my model. I can save enum property. The value is casted to int. My problem is that during data reading i get invalid cast exception. Does EF7 support enum properties ? How can i configure it with fluent api ? Thanks EDIT: enum: public enum LimitMode { Max, Min, MaxAndMin, } Model: public class SomeModel { (..) public LimitMode LimitMode {get; set;} } ModelBuilder for SomeModel: modelBuilder.Entity<SomeModel>(entity => { (

Does EF7 (EFCore) support enums?

孤人 提交于 2019-12-01 17:33:27
I have problem with EF7 RC1 (EFCore). I am unable to work with enums in my model. I can save enum property. The value is casted to int. My problem is that during data reading i get invalid cast exception. Does EF7 support enum properties ? How can i configure it with fluent api ? Thanks EDIT: enum: public enum LimitMode { Max, Min, MaxAndMin, } Model: public class SomeModel { (..) public LimitMode LimitMode {get; set;} } ModelBuilder for SomeModel: modelBuilder.Entity<SomeModel>(entity => { (...) entity.Property(p => p.LimitMode); }) This worked for me. I am using "EntityFramework

Including derived child properties in Entity Framework Core 2.0

女生的网名这么多〃 提交于 2019-12-01 17:31:31
Using Entity Framework Core 2.0, I am trying to construct a query to include related data for a polymorphic child entity. For example, given the following types: public class ParentEntity { public int Id { get; set; } public IList<ChildEntityBase> Children { get; set; } } public abstract class ChildEntityBase { public int Id { get; set; } } public class ChildEntityA : ChildEntityBase { } public class ChildEntityB : ChildEntityBase { public IList<GrandchildEntity> Children { get; set; } } public class GrandchildEntity { public int Id { get; set; } } and the following configuration: public DbSet

Database-first EF7-beta7 dnx ef dbcontext scaffold command fails

房东的猫 提交于 2019-12-01 16:42:15
In an asp.net 5 beta 7 project no matter how the command is written I get an unrecognized argument trying to scaffold the dbcontext from an existing db: C:\Dev\Project>dnx ef dbcontext scaffold provider EntityFramework.SqlServer connection "Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=ubercrew_relation;Integrated Security=True" I've tried all possible combinations of the two arguments connection and provider Do you know the right syntax for executing the scaffold command? alfberga The right command is: C:\Dev\Project>dnx ef dbcontext scaffold "Data Source=(localdb)\MSSQLLocalDB;Initial

The property 'x' is not a navigation property of entity type 'y'

独自空忆成欢 提交于 2019-12-01 15:49:05
I'm using EF Core with ASP Core 2.0. Using latest Identity framework. I get this exception on page All. InvalidOperationException: The property 'User' is not a navigation property of entity type 'Gallery'. The 'Include(string)' method can only be used with a '.' separated list of navigation property names. ApplicationUser looks like: public class ApplicationUser : IdentityUser<Guid> { public ICollection<Gallery> Galleries { get; set; } } Entity Gallery looks like: public class Gallery { public int Id { get; set; } public Guid UserId { get; set; } public string Title { get; set; } public int?

cannot update identity column in Entity Framework Core

╄→尐↘猪︶ㄣ 提交于 2019-12-01 15:05:48
问题 I've added a separate Identification to the AspNetUsers table called NumericId that will serve along with the GUID like ID that ASP has for default. I've added the property as an additional property of the ApplicationUser class: public class ApplicationUser : IdentityUser { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public virtual int NumericId { get; set; } } However, when I try to register, or update the user's details (that aren't even relevant to the numericId) I keep getting

What is the equivalent of .Configuration.ProxyCreationEnabled in EF Core?

你说的曾经没有我的故事 提交于 2019-12-01 13:48:55
What is the equivalent of .Configuration in Entity Framework Core? Receiving error below Code Examples: List<DocumentStatus> documentStatuses; using (var db = new ModelDBContext()) { db.Configuration.ProxyCreationEnabled = false; documentStatuses = db.DocumentStatus.ToList(); } using (var db = new ModelDBContext()) { db.Configuration.ProxyCreationEnabled = false; //Expression<Func<Owner, bool>> predicate = query => true; db.Configuration.ProxyCreationEnabled Error Messages throughout: Error CS1061 'ModelDBContext' does not contain a definition for 'Configuration' and no accessible extension

No nested results in Entity Framework Core [duplicate]

余生长醉 提交于 2019-12-01 11:38:51
This question already has an answer here: EF Core returns null relations until direct access 1 answer i have a strange behavior in C# with EF It's a .NET Core project with EF Core 1.1.0 "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0", "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final", I've created two Models, "User" and "Group" public class User { public int Id { get; set; } public string name { get; set; } public string lastName { get; set; } public List<Group> Groups { get; set; } } public class Group { public int Id { get; set; } public string groupName { get; set; } public