ef-core-2.0

Why reference properties works only through context

别来无恙 提交于 2019-12-07 01:55:10
问题 I have two classes Order and OrderDetail: public class Order : Entity { public Order(KitchenAppContext context) : base(context) { } public Order() : base() { } public DateTime Date { get; set; } public Guid MenuId { get; set; } public virtual Menu Menu { get; set; } public bool IsClosed { get; set; } public decimal Price { get; set; } public virtual int PeopleCount { get { return Details.Count; } } public virtual List<OrderDetail> Details { get; set; } = new List<OrderDetail>(); } public

Identity Server 4, EF Core, share DbContext between API and IS4

依然范特西╮ 提交于 2019-12-06 12:49:20
问题 I'm using Identity Server 4, Asp Identity, EF Core and one database. I have 3 projects at the moment IdentityServer - Contains all data contexts and all migrations with my app tables Api - no context, no migrations however I need to access database somehow from here Clinet - javascript The question: How do I access data context from IdentityServer project and still have all settings (db connection, etc) in one place. I understand I can reference IdentityServer from API and use data context

EF Core 2.1 slow startup

前提是你 提交于 2019-12-06 00:38:46
After having some experience with EF6 (like this ), I wanted to try out EF Core, because I've read some articles and watched some videos saying that it outperforms EF6 by a very large margin. So, I made sample program with class: public interface IEntity { int Id { get; set; } } public class Employee : IEntity { public int Id { get; set; } public string FirstName { get; set; } public string Surname { get; set; } } Then I created a repository pattern with generic repository: public interface IRepository<T> : IDisposable where T : IEntity { void Insert(T entity); void Delete(T entity);

Enabling Migrations in EF core?

♀尐吖头ヾ 提交于 2019-12-05 18:31:30
I'm getting started with EF Core 2.0, I have a console application targetting .NET 4.6.1 I have a very simple model class, and this context: public class ContextCore : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(ConfigurationManager.ConnectionStrings["efCoreCon"].ConnectionString); } public DbSet<ModelC> Models { get; set; } } this is the connection string: <add name="efCoreCon" connectionString="server=PC-MSHWF\SQLEXPRESS;database=efCoreDB;integrated security=true;" /> I noticed that there's no command for Enable

How to create CreatedOn and UpdatedOn using EF Core 2.1 and Pomelo

我只是一个虾纸丫 提交于 2019-12-05 15:49:38
In Code First approach, how to define my entity so that: CreatedOn NOT NULL - value is generated on insert by the db with the current timestamp Updated NULL - value is generated on update by the db with the current timestamp Sample Entity: public class MyEntity { public int Id { get; set; } public string Name { get; set; } [DatabaseGenerated(DatabaseGeneratedOption.Identity)] [Column(TypeName = "TIMESTAMP")] public DateTime CreatedOn { get; set; } [Column(TypeName = "TIMESTAMP")] public DateTime UpdatedOn { get; set; } } DbContext: public class MyContext : DbContext { public MyContext

Why reference properties works only through context

核能气质少年 提交于 2019-12-05 04:43:01
I have two classes Order and OrderDetail: public class Order : Entity { public Order(KitchenAppContext context) : base(context) { } public Order() : base() { } public DateTime Date { get; set; } public Guid MenuId { get; set; } public virtual Menu Menu { get; set; } public bool IsClosed { get; set; } public decimal Price { get; set; } public virtual int PeopleCount { get { return Details.Count; } } public virtual List<OrderDetail> Details { get; set; } = new List<OrderDetail>(); } public class OrderDetail : Entity { public OrderDetail(KitchenAppContext context) : base(context) { } public

Identity Server 4, EF Core, share DbContext between API and IS4

旧时模样 提交于 2019-12-04 21:51:44
I'm using Identity Server 4, Asp Identity, EF Core and one database. I have 3 projects at the moment IdentityServer - Contains all data contexts and all migrations with my app tables Api - no context, no migrations however I need to access database somehow from here Clinet - javascript The question: How do I access data context from IdentityServer project and still have all settings (db connection, etc) in one place. I understand I can reference IdentityServer from API and use data context but it seems not right to me. What is the preferred way to do this ? Since you are interested in this

Implement OrganizationUnit filter in ASP.NET Core

大城市里の小女人 提交于 2019-12-04 19:38:03
In ASP.NET Boilerplate, there are built-in Data Filters like Tenant filter, and we could use SetTenantId to enable querying specific tenantId . As per the official document, it did not support custom Filter in EF Core, unlike EF 6.x. I am wondering how to achieve a similar filter for OrganizationUnitId parameter. This is what I have done so far: Override CreateFilterExpression : protected override Expression<Func<TEntity, bool>> CreateFilterExpression<TEntity>() { Expression<Func<TEntity, bool>> expression = null; if (typeof(IMayHaveOrganizationUnit).IsAssignableFrom(typeof(TEntity))) {

EF Core 2.0 migration - Many-to-Many with additional fields

时间秒杀一切 提交于 2019-12-04 15:12:23
I'm using EF Core 2.0 and created a many-to-many relationship with a join entity. When I add a new migration EF always creates an additional Index/Id-field which is completely stupid. Here is my join entity: public class Team_Member { public int TeamId { get; set; } public Team Team { get; set; } public int MemberId { get; set; } public Member Member { get; set; } public MemberTypeEnum MemberType { get; set; } } This is the configuration of the join table (following several examples on the internet): public class Team_MemberConfig : IEntityTypeConfiguration<Team_Member> { public void Configure

EFCore nullable relationship setting onDelete: ReferentialAction.Restrict

廉价感情. 提交于 2019-12-04 00:26:48
问题 I'm running efcore 2.0.1. I have a model: public class BigAwesomeDinosaurWithTeeth { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } public ICollection<YummyPunyPrey> YummyPunyPrey { get; set; } } public class YummyPunyPrey { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } public Guid? BigAwesomeDinosaurWithTeethId { get; set; } [ForeignKey("BigAwesomeDinosaurWithTeethId")] public BigAwesomeDinosaurWithTeeth