entity-framework-core

Update-Database command is not working in ASP.Net Core / Entity Framework Core because object in database already exists

你离开我真会死。 提交于 2019-12-04 09:55:09
I was updating my database by the command line, but then I manually updated one of my tables. This seems to have disrupted my ability to update-database. I receive the following error when I try to update: System.Data.SqlClient.SqlException: There is already an object named 'ClientsAndTestimonials' in the database. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data

ASP.NET Core EF Add-Migration command not working

有些话、适合烂在心里 提交于 2019-12-04 09:53:39
问题 Following this Microsoft Tutorial when I run the PM> Add-Migration MyFirstMigration command in VS2015 project created from the same tutorial I get the following error that I can't resolve: More than one DbContext was found. Specify which one to use. Use the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands. Point to note I'm using the above tutorial with the exception that I'm using Individual User Account authentication instead of No

Entity Framework Core Migration for ASP.Net Core Class Library

三世轮回 提交于 2019-12-04 09:24:39
I've been trying to follow the advice of Ben Cull ( http://benjii.me/2016/06/entity-framework-core-migrations-for-class-library-projects ), but the database is a little different in that I'm trying to inherit from ASP.NET Core IdentityUser class. I created a new solution containing the default ASP.NET Core Web Application from the VS2015 template (CodeFirstTest). I then added an ASP.NET Core class-library (CodeFirstTest.User) to the solution, which would be the data layer in the application and where I will also be setting up ASP.NET Core Identity. Following the advice of Ben Cull, I rewrote

Better way to implement a row version with EF Core and MySQL?

本秂侑毒 提交于 2019-12-04 08:50:32
If I use the following field in my model: [DatabaseGenerated(DatabaseGeneratedOption.Computed)] [Timestamp] public DateTime RowVersion { get; set; } and then define the column as `RowVersion` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP I get the proper optimistic concurrency behavior from EF. That said, I'm not thrilled about using a timestamp for this since it appears to only be second resolution. And while there isn't a big chance of having 2 clients try to update the same record within 1 second, it certainly could happen, no? So with that in mind I would prefer a

Entity Framework Core add unique constraint code-first

 ̄綄美尐妖づ 提交于 2019-12-04 07:52:13
问题 I can't find way to add a unique constraint to my field with using attribute: public class User { [Required] public int Id { get; set; } [Required] // [Index("IX_FirstAndSecond", 2, IsUnique = true)] not supported by core public string Email { get; set; } [Required] public string Password { get; set; } } I'm using these packages: "Microsoft.EntityFrameworkCore": "1.0.1", "Microsoft.EntityFrameworkCore.SqlServer": "1.0.1", "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.1", "Microsoft

How to group by week in Entity Framework Core?

巧了我就是萌 提交于 2019-12-04 07:43:27
In Entity Framework 6 I can use SqlFunctions.DatePart() method: var byWeek = data.GroupBy(x => SqlFunctions.DatePart("week", x.Date)); But these classes ( DbFunctions and SqlFunctions are not available in Entity Framework Core) ( reference ). So my question is How can I group by week in Entity Framework core? My current workaround for the missing functionality is var firstMondayOfYear = this.GetFirstMondayOfYear(DateTime.Now.Year); var entries = this.entitiesService.FindForLastMonths(this.CurrentUser.Id, 6) .GroupBy(x => ((int)(x.Date - firstMondayOfYear).TotalDays / 7)) The function

Entity Framework Core 2.1 throwing ArgumentException on left join

此生再无相见时 提交于 2019-12-04 07:19:46
I recently upgraded my project from .NET Core 2.0 to 2.1. I use Entity Framework Core and have several LINQ expressions that include left joins. The following code is an example: var tickets = (from ticket in dbContext.Tickets join member in dbContext.Members on ticket.MemberID equals member.ID into memberLEFT from member in memberLEFT.DefaultIfEmpty() join memberType in dbContext.MemberTypes on member.MemberTypeID equals memberType.ID into memberTypeLEFT from memberType in memberTypeLEFT.DefaultIfEmpty() select memberType) .ToList(); If .NET Core 2.0, this line executed with no exceptions. In

Store files in database using Entity Framework Core

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 06:25:10
How to store files in a SQL Server database using Entity Framework Core (Code-First) in an ASP.NET Core app? I have tried using Filestream but unfortunately I get this error: Cannot call Property for the property 'Avatar' on entity type 'UserProfile' because it is configured as a navigation property. Property can only be used to configure scalar properties Here's the code: public class UserProfile : BaseEntity { public FileStream Avatar { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public DateTime DateOfBirth { get; set; } public Sex Sex { get; set; }

Entity Framework ChangeTracker Stream and Save to Query Afterwards

可紊 提交于 2019-12-04 06:23:51
问题 I want to validate when certain Entity is Modified/Updated/Inserted/Deleted in Entity Framework (with database). (eg ProductType Entity table) ** Would like Change Tracker to be saved and queried later, as 'the track changes are lost if they are not saved before the DbContext object is destroyed.' Only need ChangeTracker to be retained for couple hours most to analyze, and be saved in MessageQueue if needed. MemoryCache can also work. 1) Someone recommend using LoggerFactory: optionsBuilder

Identity Server 4 Claims empty on API

若如初见. 提交于 2019-12-04 05:18:24
问题 I have been trying to Integrate Identity Server 4 with SPA application. I am able to Authorize the Application in API but after the authorization the User.Claims are always empty though i have added the Claims in Scopes. I am using Asp.net Identity in API with entity framework core. My project are distributed in different projects. Project.Auth (using Identity Server 4) Project.Admin Project.Data (where my Context and Migration Lies) Project.Domain(Enities) Project.Service(Repository and