ef-migrations

Can you create sql views / stored procedure using Entity Framework 4.1 Code first approach

你离开我真会死。 提交于 2019-11-26 09:21:09
问题 Entity Framework 4.1 Code First works great creating tables and relationships. Is it possible to create sql views or stored procedure using Code first approach? Any pointers regarding this will be highly appreciated. Thanks a lot! 回答1: EF code-first approach expects that there is no logic in the database. That means no stored procedures and no database views. Because of that code-first approach doesn't provide any mechanism to generate such constructs automatically for you. How could it do

Mapping Database Views to EF 5.0 Code First w/Migrations

懵懂的女人 提交于 2019-11-26 08:28:14
问题 I\'m trying to map a SQL View to an entity in EF 5.0 Code First w/Migrations for displaying some basic information on a page without having to query multiple tables for that information (which currently takes ~20 seconds to load. NOT GOOD. ). I\'ve heard that it is possible to do, but I haven\'t been able to figure out or find online a way to properly do so. EDIT: For a more in-depth look at my solution to this problem, read this blog post on the subject. Here is my View: CREATE VIEW [dbo].

GUID COMB strategy in EF

戏子无情 提交于 2019-11-26 08:26:27
问题 Is there any way to implement the Guid COMB identity strategy for objects in the new Entity Framework 4.1 using the CodeFirst design? I thought setting the StoreGeneratedPattern would work, but it still gives me normal GUIDs. 回答1: I guess you are using SQL server as your database. This is nice example of inconsistency among different MS tools. SQL server team doesn't recommend using newid() as default value for UNIQUEIDENTIFIER columns and ADO.NET team use it if you specify Guid property as

Possible to default DateTime field to GETDATE() with Entity Framework Migrations?

此生再无相见时 提交于 2019-11-26 08:21:07
问题 I added EntityFramework.Migrations (Beta 1) to an existing Code-First app that is going through some changes (for both migration capabilities and more fine-tuning of the tables I am generating from my code-first API) and ran into the GETDATE() scenario. I was already using a custom initializer class in my DbContext to run SQL scripts to set some fields and create indexes in my database. A handful of my AlterTable scripts are primary just to setup fields with default values(such as certain

There is already an object named in the database

时间秒杀一切 提交于 2019-11-26 07:58:10
问题 Update-Database failed from Package Manager Console. I\'ve used Entity Framework 6.x and code-first approach. Error is \"There is already an object named \'AboutUs\' in the database.\" How can I solve this problem? internal sealed class Configuration : DbMigrationsConfiguration<Jahan.Blog.Web.Mvc.Models.JahanBlogDbContext> { public Configuration() { AutomaticMigrationsEnabled = true; AutomaticMigrationDataLossAllowed = false; } protected override void Seed(Jahan.Blog.Web.Mvc.Models

MVC 5 Seed Users and Roles

天涯浪子 提交于 2019-11-26 07:56:47
问题 I have been playing about with the new MVC 5, I have a few models, controller and views setup using code first migrations. My question is how do I seed users and roles? I currently seed some reference data in my Seed method in Configuration.cs. But it looks to me that the user and roles tables are not created until something first hits the AccountController. I currently have two connection strings so I can separate my data from my authentication into different databases. How can I get the

MVC3 and Code First Migrations - “model backing the &#39;blah&#39; context has changed since the database was created”

不羁岁月 提交于 2019-11-26 06:38:17
问题 I started off my project by using Entity Framework Code First. When I was ready I uploaded my database and code to my host provider. Everything worked. I need to add a new field to one of my classes and I don\'t want to loose the data in the database. Thus, I tried following some blog posts about using Code First Migrations. I did the following: I backed up my remote (production) database. I attached this database locally I added the property to my class PM> Enable-Migrations PM> Add

Using Entity Framework (code first) migrations in production

梦想与她 提交于 2019-11-26 04:05:24
问题 I\'m just looking into using EF migrations for our project, and in particular for performing schema changes in production between releases. I have seen mentioned that there is an API to perform these migrations at run-time using the DbMigration class, but I can\'t find any specific examples. Ideally, I would want one DbMigration file for every database change, and for those changes to be applied automatically on application start up from the current version up to the latest version. 回答1:

EntityFramework code-first custom connection string and migrations

浪子不回头ぞ 提交于 2019-11-26 03:54:52
问题 When I create a context with a default connection string (as read from the app.config ) the database is created and the migrations work - basically everything is in order. Whereas when the connection string is created programatically (using SqlConnectionStringBuilder ): database isn\'t created when the database is not present (scenario A ); CreateDbIfNotExists() creates the newest version of database model but the migration mechanisms are not invoked (scenario B ). In A an exception is thrown

Reset Entity-Framework Migrations

只谈情不闲聊 提交于 2019-11-26 00:45:16
问题 I\'ve mucked up my migrations, I used IgnoreChanges on the initial migration, but now I want to delete all my migrations and start with an initial migration with all of the logic. When I delete the migrations in the folder and try and Add-Migration it doesn\'t generate a full file (it\'s empty - because I haven\'t made any changes since my last, but now deleted, migration). Is there any Disable-Migrations command, so I can rerun Enable-Migrations ? 回答1: You need to : Delete the state: Delete