ef-core-2.0

Rename a foreign key in Entity Framework Core without dropping data

落爺英雄遲暮 提交于 2019-12-03 07:56:27
I have two model classes: public class Survey { public int SurveyId { get; set; } public string Name { get; set; } } public class User { public int UserId { get; set; } public int SurveyId { get; set; } public Survey Survey { get; set; } } I want to rename Survey to StudentSurvey , so it will have StudentSurveyId . I update the class name and the properties in the models accordingly and add a migration. However, I get: The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_User_Surveys_SurveyId". The conflict occurred in database "AppName", table "dbo.Survey", column

Multiple connection to DbContext in EFCore and .net Core2.0

只谈情不闲聊 提交于 2019-12-03 00:51:46
问题 I have facing a problem to connecting to DBcontext with multiple connection. please help me out from this problem , here is me scenario . I have an Angular5 application and Webapi Controllers. I have 4 databases and Each database has different users . When 4 user are trying to connecting to their database at Same time through Webapi controller , that time all users are getting data from single database (instead of getting different database ) . When we try to Connecting one by one then data

Multiple connection to DbContext in EFCore and .net Core2.0

杀马特。学长 韩版系。学妹 提交于 2019-12-02 13:25:53
I have facing a problem to connecting to DBcontext with multiple connection. please help me out from this problem , here is me scenario . I have an Angular5 application and Webapi Controllers. I have 4 databases and Each database has different users . When 4 user are trying to connecting to their database at Same time through Webapi controller , that time all users are getting data from single database (instead of getting different database ) . When we try to Connecting one by one then data getting correctly . Here is my sample code for dynamic connection . Context Connectionstring : protected

What is the replacement for hasRequired with EF core?

一曲冷凌霜 提交于 2019-12-02 12:00:04
问题 With entity framework we had hasRequired on a field. what is the alternative replacement for that with EF core? https://msdn.microsoft.com/en-us/library/jj591620(v=vs.113).aspx i tried with hasRequired, but it throws error. 回答1: Check out the Required and Optional Relationships in the EF Core Documentation. Specifically I think you'll want something like: protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<MyEntity>() .HasOne(p => p.Relationship)

Which one must I use, MyDbContext.Blogs.Add(ablog) or MyDbContext.Add(ablog)?

好久不见. 提交于 2019-12-02 06:43:35
Consider I have a context MyDbContext inherits DbContext of EFCore 2.0. Blogs is a DbSet<Blog> and Blog is an entity model. When I add a new Blog instance, ablog to the Blogs , which one must I use? MyDbContext.Add(ablog); or MyDbContext.Blogs.Add(ablog); ? How about Find ? MyDbContext.Find<Blog>(1); or MyDbContext.Blogs.Find(1); ? Is there any benefit to use one over the other one? Adding directly data via the DbContext is new to the DbContext in Entity Framework Core and have no equivalents in previous version of Entity Framework where the DbContext is available (i.e. EF 4.1 onwards). But

What is the replacement for hasRequired with EF core?

瘦欲@ 提交于 2019-12-02 04:26:42
With entity framework we had hasRequired on a field. what is the alternative replacement for that with EF core? https://msdn.microsoft.com/en-us/library/jj591620(v=vs.113).aspx i tried with hasRequired, but it throws error. Check out the Required and Optional Relationships in the EF Core Documentation. Specifically I think you'll want something like: protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<MyEntity>() .HasOne(p => p.Relationship) .IsRequired(); } Or something like that - you haven't given much information to go on 来源: https://stackoverflow.com

How to remove the role-related tables from ASP.NET Identity Core 2.0

匆匆过客 提交于 2019-12-02 03:10:18
With the advice read-elsewhere that Roles are a subset of Claims, I am looking at a clean way to ask the EF Core implementation in ASP.NET Identity not to create role-related tables in the ASP.NET Identity Core 2.0 template in VS 2017. Only claims are needed. The template uses public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); // Customize the ASP.NET Identity model and override the

Scaffold-DbContext “The method or operation is not implemented”

﹥>﹥吖頭↗ 提交于 2019-12-01 15:01:29
Not having a great time. PM> command run Scaffold-DbContext "Server=myserver;Database=mysqlserverdb;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -Tables Settings -verbose Error: The method or operation is not implemented. System.NotImplementedException: The method or operation is not implemented. at Microsoft.EntityFrameworkCore.Scaffolding.ProviderCodeGenerator.GenerateUseProvider(String connectionString) at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpDbContextGenerator.GenerateOnConfiguring(String connectionString, Boolean suppressConnectionStringWarning) at

Scaffold-DbContext “The method or operation is not implemented”

允我心安 提交于 2019-12-01 12:54:45
问题 Not having a great time. PM> command run Scaffold-DbContext "Server=myserver;Database=mysqlserverdb;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -Tables Settings -verbose Error: The method or operation is not implemented. System.NotImplementedException: The method or operation is not implemented. at Microsoft.EntityFrameworkCore.Scaffolding.ProviderCodeGenerator.GenerateUseProvider(String connectionString) at Microsoft.EntityFrameworkCore.Scaffolding.Internal

How do I finalize a class based Saga, so that it is deleted from the SQL database (EF Core)?

断了今生、忘了曾经 提交于 2019-12-01 12:40:36
I am trying to learn more about Mass Transit as we are thinking about adopting it. I now have the class based Saga below, which works as expected: public class EchoSaga : ISaga, InitiatedBy<TextEntered>, Orchestrates<TextEchoStart>, Orchestrates<EchoEnd> { public Guid CorrelationId { get; set; } public string CurrentState { get; set; } public string Text { get; set; } public Task Consume(ConsumeContext<TextEntered> context) { CurrentState = "Entered"; Text = context.Message.Text; return Task.CompletedTask; } public Task Consume(ConsumeContext<TextEchoStart> context) { CurrentState = "Start";