ef-migrations

Entity Framework : Sharing entities across different DbContexts

梦想与她 提交于 2019-11-29 08:20:26
问题 I'm developing a plugin application with EF6, code first. I have one main context with an entity called User : public class MainDataContext : DbContext { public MainDataContext(): base("MainDataContextCS") {} public DbSet<User> Users { get; set; } } And then another context for PluginX, on another project which references the base one: public class PluginDataContext : DbContext { public PluginDataContext () : base("MainDataContextCS") { } protected override void OnModelCreating(DbModelBuilder

Unable to run EF5 migration with existing database

我的未来我决定 提交于 2019-11-29 06:56:07
First, I've read these questions/answers: EF-migration message How can I stop Add-Migration checking my database has no pending migrations when using Code-Based migrations? Make EF4.3 Code First Migrations ignore pending migrations These all seem to be for EF versions prior to EF5, and my situation doesn't seem to fit these answers. So, let me describe my situation. My application was originally created using EF4, model first. I designed my database with the GUI designer, and used it to generate my database. I've been running and collecting data into the database for a few months. I really can

How to make persisted computed column in EF code first?

回眸只為那壹抹淺笑 提交于 2019-11-29 06:53:03
How do I get this column as similar to a PERSISTED COMPUTED column in the database? My current attempt (it loads all CompCol rows with null in seed) : public class Call { public Call() { } [Key] public int Id { get; set; } [DatabaseGenerated(DatabaseGeneratedOption.Computed)] public string CompCol { get { return "ABC-" + Convert.ToString(Id).PadLeft(5, '0'); } protected set {} } } The solution I found was to : Make sure auto migrations are turned off. This is so that VS will generate a script (fluent api code) for us to further customise instead of just running it. So in the configuration

Changing column default values in EF5 Code First

若如初见. 提交于 2019-11-29 06:15:27
I'm trying to use CF to build a model for an existing database. I have a column in which I forgot to set a sane default value. And rather than compromise the purity of the initial migration by changing it, I just figured I'd create another migration (that's what migrations are for, right? :) public override void Up() { AlterColumn("Config", "DefaultTaxPerDollar", c => c.Decimal(nullable: false, precision: 19, scale: 5, defaultValue: 0.087m)); } public override void Down() { AlterColumn("Config", "DefaultTaxPerDollar", c => c.Decimal(nullable: false, precision: 19, scale: 5, defaultValue: 0.0m)

MultiTenant Application Prevent Tenant Access Data from Other Tenant in Shared Database

ぃ、小莉子 提交于 2019-11-29 05:16:27
I’m working on a tenant application and i was wondering how i can block tenant access other tenant data. First, let me expose some facts: The app is not free, 100% for sure the malicious user is a client. All the primary keys/identity are integers (Guid solve this problem but we can't change right now). The app use shared database and shared schema. All the tenants are business group wich own several shops. I'm use Forgery... I have some remote data chosen by dropdown and its easy change the id's and acess data from other tenants, if you have a little knowledge you can f*ck other tenants data.

Code first migrations - how to display pending model changes?

拥有回忆 提交于 2019-11-29 05:14:51
问题 I'm using code first migrations. Is there a way to display pending model changes in package manager console before I scaffold a new migration? 回答1: There is no way that I know of to view pending changes in the model before scaffolding the migration, but I can't think of a reason not to scaffold the migration using Add-Migration so that the pending changes can be viewed in the migration file. There is no need to apply those changes to the database and the scaffolded migration can always be

What is a Discriminator column in ASP.NET Migrations?

空扰寡人 提交于 2019-11-29 02:56:49
问题 I needed to add an extra field to Role identity table in ASP.NET MVC 5. I use migrations. I have added an extension to role like: public class ApplicationRole : IdentityRole { public ApplicationRole() : base() { } public ApplicationRole(string name) : base(name) { } public virtual Project Project { get; set; } } My migration class, I'm getting is: public partial class ProjectToIdentity : DbMigration { public override void Up() { CreateTable( "dbo.Projects", c => new { ID = c.Int(nullable:

Cannot enable migrations for Entity Framework in class library

随声附和 提交于 2019-11-29 02:48:15
I just got on board with EF 5 and am using their code-first migrations tool but I seem to get an error when I try to enable migrations. I type Enable-Migrations into the package manager console and then it says No classes deriving from DbContext found in the current project. Edit the generated Configuration class to specify the context to enable migrations for. Code First Migrations enabled for project MyApp.MvcUI. It then creates a Migrations folder and a Configuration class in my MvcUI project. Thing is, my DbContext lives in a class library project called MyApp.Domain. It should be doing

Automatically execute migrations when publishing ASP.NET Core app

℡╲_俬逩灬. 提交于 2019-11-29 02:19:33
Question Is there any ways that I can automatically execute the migration code (EF 7) when publishing my ASP 5 application to IIS using Web Deploy? I Tried in the project.json , I added this code in the scripts : "scripts" : { "prepublish": ["dnx ef database update", "other commands..."], "postpublish": ["dnx ef database update"] } none worked for me. Additional Info I followed the instructions on this link to deploy my ASP 5 RC-1 web application to IIS using web deploy. After doing so in the publish settings I have: Using web deploy in ASP 4 applications I have additional database options:

What is the correct format for Running Entity Framework migrate.exe tool without a Web/App.config?

安稳与你 提交于 2019-11-29 02:03:31
问题 We recently switched to Entity Framework data migrations and I am working on some build automation scripts for our MVC app. I can successfully run the migrations from our build server using the migrate.exe tool in 4.3 if I have a Web.config to point it at. The command looks something like: ProjectName\packages\EntityFramework.4.3.1\tools\migrate.exe MyAssembly /startupdirectory:ProjectName\bin\Debug /startupconfigurationfile:ProjectName\Web.config /verbose However, for various reasons I would