ef-migrations

Entity Framework 6 (EF6) code first migrations with models in separate project

假如想象 提交于 2019-12-12 02:06:05
问题 Using EF6 code-first migrations, I am able to successfully save models and create new migrations for them. However, my DbContext class is in a Sharp.Data project, the actual (Sql CE) database lives under the Sharp.Server project bin folder, and my models live in a Sharp.Common project. When I run add-migration -ProjectName Sharp.Data Migration3 (pointing to Sharp.Data as that is where the DbContext is), it successfully runs and identifies changes made to the models in the Sharp.Common project

Do not create existing table during Migration

喜你入骨 提交于 2019-12-12 01:42:48
问题 I am using entity to connect to an existing database using code first migrations. In the database I need to connect to a few tables that already exist and add a few new ones. I thought I had it figured out but it is still trying to create the tables that already exist. Here is the model of one of the tables: namespace PTEManager.Domain { public partial class OpsUser { public int u_user_id { get; set; } public Guid DepartmentID { get; set; } public string email_addr { get; set; } public string

Data Seed failed in hosted project in linux server. Asp .net core 2.1

╄→гoц情女王★ 提交于 2019-12-12 01:19:28
问题 I hosted my project in ubunto 18.4 version server.All configurations done after it's not working,in the browser it shows 503 error. when I try to manually execute .dll file it show some errors. Could not resolve a service of type 'SocialApp.API.Data.Seed' for the parameter 'seeder' of method 'Configure' on type 'SocialApp.API.Startup'. ---> System.ArgumentNullException: Value cannot be null. Parameter name: connectionString here is the full error code Microsoft.AspNetCore.DataProtection

How to set on delete cascade for self reference Foreign Key in Entity Framework in ASP.NET

自古美人都是妖i 提交于 2019-12-11 19:28:42
问题 I am developing an ASP.NET MVC project. I am using Entity Framework code first approach to interact with database. But I am having a problem with setting on cascade delete for self-reference foreign key for an entity. This is my entity class with self reference foreign key public class Category { public int Id { get; set; } [Required] [MaxLength(50)] public string Name { get; set; } [MaxLength(55)] public string MmName { get; set; } public int? ParentId { get; set; } [ForeignKey("ParentId")]

Use custom logic in EF Code First migration

狂风中的少年 提交于 2019-12-11 19:06:49
问题 I have an existing Database with a some amount of data (i.e. DB is not empty). Now I made a decision to encrypt some sensitive data. I have a column TemplateBlocks : string . I'm going to replace it with new column TemplateBlocksEnc : byte[] and I did properly changed my Code First model. Then I generated migration and ... stuck! public partial class EncryptTemplateBlocks : DbMigration { public override void Up() { AddColumn("dbo.Devices", "TemplateBlocksEnc", c => c.Binary(nullable: true));

Storing list of objects in a SQL Server database with code-first

冷暖自知 提交于 2019-12-11 13:58:31
问题 Example Let's say the number of answers of multiple choice questions varies. One question can have only 2 choices while another can have 10 choices. How can I save these multiple choice questions in my SQL Server database? Is the following model viable? public class MultipleChoiceQuestion { [Key] public Guid Id { get; set; } [Required] public string Question { get; set; } // Suppose I can have 2-10 answers [Required] public List<string> Answers { get; set; } } Question Can we store a list of

Entity Framework code first seems confused on my dbo table names after I tweaked the migration file

醉酒当歌 提交于 2019-12-11 12:56:47
问题 I've just begun using Entity Framework 5 (Code First Migrations). I think my issue may just be a given to someone that's worked with this a bit longer than I have (this is our first project giving it a go). I have 3 tables involved. One is a cross reference table. The gist of the classes is as follows: public class Person { //person properties public virtual List<Roles> Roles {get;set;} } public class Role { //Role properties public virtual List<Person> Persons {get;set;} } Adding a migration

Using Foreign Keys with different Contexts using Entity Framework code-first

雨燕双飞 提交于 2019-12-11 12:35:09
问题 I have a brand-new ASP.NET MVC 5 project with one DbContext using Entity Framework 6.1 and Identity 2.2.1. Trying go use IoC, I created a 2nd DbContext and some classes belonging to that 2nd context. Most of these classes have a foreign key to the IdentityUser class within Identity 2.2.1. The problem I'm having is that when I try to use Add-Migrations I get the following error: One or more validation errors were detected during model generation: {MyProjectName}.DataContexts.IdentityUserLogin:

BadImageException using update-database

回眸只為那壹抹淺笑 提交于 2019-12-11 11:42:30
问题 I have an assembly with an EF 5.0 (target framework 4.0) migrations in it. When I open the package management console and type 'update-database' I get an BadImageException. (note: I have one c++ native lib in the solution). I have read several post regarding this and I tried: All projects have x64 target platform Solution platform is x64, all projects have x64 as configuration No warnings during build But...when I added a console app, using DBMigrator class the migration works fine! What

Code First Migration Entity Framework 6 Empty Up/Down

戏子无情 提交于 2019-12-11 10:40:08
问题 The problem I'm having is that when I "Add-Migration", it seems that no comparison against the target database is done and the Up/Down methods are empty. This starts from me targeting different environments. The migration changes work fine when I update-database and it targets one particular database, my dev database. When I change the connection string to target another database, another dev box on another server, and try to add-migration for that particular environment, the Up/Down methods