entity-framework-core

Add-Migration fails because EntityFrameworkCore.Tools is not installed

别说谁变了你拦得住时间么 提交于 2019-12-04 14:25:35
I want to create a console application with EF Core by following this tutorial: http://ef.readthedocs.io/en/latest/platforms/full-dotnet/new-db.html . My problem is, I cannot execute the statement Add-Migration as described in the tutorials. It shows me: PM> Add-Migration MyFirstMigration Cannot execute this command because 'Microsoft.EntityFrameworkCore.Tools' is not installed in project 'src\AppEf'. Add 'Microsoft.EntityFrameworkCore.Tools' to the 'tools' section in project.json. See http://go.microsoft.com/fwlink/?LinkId=798221 for more details. All added assemblies: What is wrong? Update

Avoid 'Discriminator' with AspNetUsers, AspNetRoles, & AspNetUserRoles

不羁的心 提交于 2019-12-04 14:03:08
I am extending IdentityUser , IdentityUserRole , and IdentityRole like this: public class ApplicationUser : IdentityUser { public string FullName { get; set; } public virtual ICollection<ApplicationIdentityUserRole> Roles { get; } = new List<ApplicationIdentityUserRole>(); } public class ApplicationIdentityUserRole : IdentityUserRole<string> { public virtual ApplicationUser User { get; set; } public virtual ApplicationRole Role { get; set; } } public class ApplicationRole : IdentityRole { public virtual ICollection<ApplicationIdentityUserRole> Roles { get; } = new List

How do I run ASP.NET Core Entity Framework migrations from Visual Studio Team Services

此生再无相见时 提交于 2019-12-04 13:54:29
I've got a Web API project created using ASP.NET Core 1.1. I use Entity Framework Core Migrations. Locally, that all works well. However, I'm trying to use Visual Studio team services to automatically run the migrations when I do a release and can't figure out how to do this. Is there some inbuilt component, or should I try to get the dotnet ef tools installed on the agent and run it that way? I would suggest using the dotnet ef tools (during VSTS Build) to generate a .sql script which could be used to generate or update your database wherever needed (during the Release). dotnet ef migrations

.net core - unit of work generic repository pattern

£可爱£侵袭症+ 提交于 2019-12-04 13:17:02
I am Looking to migrate a large project that gathers information about products. The current application uses CSLA as its framework (traditional aspx forms). I am wanting to migrate / develop the application over to .net core 2.1. I have experience of developing in MVC (4+ years) and some recent exposure to .net core. I am wanting to use EF Core to call the existing stored procedures. I am looking at using the Unit of Work Generic repository design pattern. I have used the repository pattern before and found it very useful. As part of the functionality that exists within the current process,

Show Original Values Entity Framework 7

久未见 提交于 2019-12-04 12:30:59
I have an audit table that tracks Added, Deleted and Modified. I track this inside Entity Framework instead of using a Database trigger for multiple reasons but really because we use a Process Account and I want to track what user physically made that change to that record. I had this working in with EF 5 & I cannot remember I might have had it working in EF6 as well. Either way I am having the hardest time with EF 7 trying to capture the original values. I noticed that when I am in the watch - I can see Original Values inside the Non-public members - so in my head I know it has to exist

Is it possible to intercept a READ action?

我与影子孤独终老i 提交于 2019-12-04 11:28:41
In Entity Framework Core, you can override SaveChanges / SaveChangesAsync method in the DbContext and based on different states like: EntityState.Added or EntityState.Modified or EntityState.Deleted , you can create some Audit solution about when and whom created, modified or deleted certain records. You can save the state of the entity before and after the action. All good here works perfect! Can we do something similar for read/query/select/view actions? I dug a little and found that the actual execution of the IQueryable is done by EntityQueryProvider : IAsyncQueryProvider, IQueryProvider .

EF Core / DbContext > Map custom type as primary key

主宰稳场 提交于 2019-12-04 10:56:34
Using the fluent api, how do I map a custom type as the primary key within my OnModelCreating method of the DbContext class? Using EF Core I'm trying to build a model for the follow entity. public class Account { public AccountId AccountId { get; } public string Name { get; set; } private Account() { } public Account(AccountId accountId, string name) { AccountId = accountId; Name = name; } } Where the primary key is the AccountId ; the type is a simple value object like this. public class AccountId { public string Id { get; } public AccountId(string accountId) { Id = accountId; } } Within

what is the difference between use dbset and mappers in EF7

╄→гoц情女王★ 提交于 2019-12-04 10:47:32
I started to work with .net core and Entityframework 7 in Onion Architecture ! i readed this tutorial and i think its best case for learning following subject. but one part of this tutorial made a big question inside my brain. like what you see at this linked page; at Data Layer we have some classes which are our model!! public class User : BaseEntity { public string UserName { get; set; } public string Email { get; set; } public string Password { get; set; } public virtual UserProfile UserProfile { get; set; } } public class UserProfile : BaseEntity { public string FirstName { get; set; }

Pattern for caching data in Asp.Net Core + EF Core?

穿精又带淫゛_ 提交于 2019-12-04 10:46:21
I have an Asp.Net Core + EF Core REST service. I created a DbContext class for a DB I want to call a SP on. The method pretty much looks like: public IQueryable<xxx> Getxxxs() { return Set<xxx>().FromSql("pr_Getxxx"); } This all works, but there isn't any point in calling the SP every single time since the data the SP returns rarely changes. I'd like to make the data stale, say every 24 hours. Is there a preferred pattern for doing that in Core? I see they have the .AddCaching extension method, but that seems like it would get injected into the controller? So its the controllers job to cache?

EF: The instance of entity type X cannot be tracked because another instance of this type with the same key is already being tracked

给你一囗甜甜゛ 提交于 2019-12-04 10:41:28
I am sending a User entity in Json format in my http request like this: POST http://localhost:52054/api/Authentication/DeleteAccessToken HTTP/1.1 Host: localhost:52054 Content-Type: application/json {"id":1,"userName":"mnoureldin","accessToken":{"id":1,"token":"123ABC456EFG","userId":1}} And my controller (in EF-core ) handles that like this: [HttpPost] public IActionResult DeleteAccessToken([FromBody]User user) { using (var Context = new UnitOfWork().Context) { var userEntity = Context.Users.Find(user.Id); // Get the real entity of the user received as json if (userEntity != null) { var