Tag: 代码优先迁移

更改数据库迁移中的存储过程EF 6 Code First – 如何为参数默认传递null

我正在使用空迁移来更新我的数据库中的存储过程。 存储过程是在数据库的初始创建中添加的自定义存储过程。 我在DbMigration类中发现了’AlterStoredProcedure’方法,这可以更新存储过程,但是我必须通过存储过程的参数,我想设置一个布尔值的默认值,并将一些int设置为null,但我似乎无法让这个工作。 AlterStoredProcedure( name: “[dbo].[FT_People_PersonFullTextSearch]”, parametersAction: p => new { searchTerm = p.String(600), isArchived = p.Boolean(false), isActive = p.Boolean(null), genderFilter = p.Int(null), rankingFilter = p.Int(null) }, body: “the body of my stored proc….”); 上面的代码产生 ALTER PROCEDURE [dbo].[FT_People_PersonFullTextSearch] @searchTerm [nvarchar](600), @isArchived [bit] = 0, @isActive [bit], @genderFilter [int], @rankingFilter [int] AS BEGIN 代替 ALTER PROCEDURE […]

在程序集中找不到上下文类型。 ASP.NET MVC4

在这里遵循这个教程(根据教程需要一个客户数据库而不是电影): http : //www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-a -新场到了,电影模式和表 但是,当我尝试运行迁移命令时,会遇到以下错误:“在程序集’MvcVault’中找不到上下文类型’MvcCustomer.Models.CustomerDbContext’。” 这是我的客户模型: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.Entity; namespace MvcVault.Models { public class Customer { public int ID { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public DateTime Born { get; set; } public int Telephone […]

entity framework代码优先迁移的例外情况

我在使用Entity Framework 4.3的Code First Migrations时遇到了几个未处理的exception。 数据库上下文: public class MyAppContext : DbContext { public DbSet Branches { get; set; } public MyAppContext() { } } 实体: public class Branch : IEntity { public Guid Id { get; set; } public string Name { get; set; } public string Description { get; set; } public bool Active […]

EF6:使用Code First Migrations重命名命名空间

我可以重命名整个Project的命名空间(当然包括:DbContext类,迁移配置类等),而不会破坏任何内容或不得不重新创建我的所有迁移? 说,我有Project MyProject,命名空间是 Foo.MyProject 我的配置类在 Foo.MyProject.Migrations 假设我想为Bar重命名Foo命名空间,当然我的配置命名空间现在将是 Bar.MyProject.Configurations 有没有正确的方法来保持我目前的所有迁移仍然有效? 这些方法是否涉及手动编辑___MigrationHistory表或其他什么? (一眼就能看到ContextKey列,我怀疑我应该手动编辑。)

EF Code First – 超时已过期。 完成前经过了超时时间

为这个措辞奇怪的问题道歉。 我不知道实际问题是什么,但希望有人可以给我一些见解。 尝试运行迁移时出现以下错误: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. —> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out 值得注意的是,在我的笔记本电脑上,这种情况并没有发生,但在我的VM(azure色 – 大)上,这种情况发生在100%的故障率上。 我使用的是Ef 6.0.0 -rc1 。 请注意,更新EF不是一个选项。 如果更新到EF 6.0.0或6.0.1,我将收到以下错误,100%失败率: Code First添加迁移期间的错误 我也计时了错误。 触发错误大约需要1.5分钟。 当使用-Verbose标志运行时,它试图创建200个带索引的表。 复制sql查询并在SSMS中将其排除需要5秒。 我厌倦但没有用的一些事情: 1)设置ObjectContext.CommandTimeout = 36000 // 10 hours! 如下所示: https://stackoverflow.com/a/6234593/305469 2)在“web.config”中设置连接字符串中的超时: […]

错误:项目上未安装EntityFramework包

我刚刚安装了SQL Server 2008,将我的ASP.NET MVC 4项目配置为部署在本地IIS,并添加了一个新的连接到数据库(在sql server 2008中)。 当我尝试通过Package Manager控制台中的 Enable-Migrations -ContextTypeName MonitoringNDataContext启用迁移(entity framework)时。 我得到以下错误: 项目’MonitoringN.Tests’上未安装EntityFramework包。 请问有什么好主意吗? MonitoringN:命名ASP.NET MVC 4项目。 MonitoringNDataContext:放入MonitoringN的我的DBContext类的名称。 MonitoringN.Tests:与MonitoringN相关的unit testing项目的名称。

entity framework – 如何在种子方法中获取相对文件路径

为什么filePath为null? 有关如何获取相对filePath的任何想法? internal sealed class Configuration : DbMigrationsConfiguration { public Configuration() { // code here is not relevant to question } protected override void Seed(MvcProject.Models.FileDb context) { string filePath = System.Web.HttpContext.Current.Server.MapPath(“~/Content/File.txt”); // read File.txt using filePath and update the database } } 我在ASP .NET MVC项目上设置entity framework时创建的Migrations文件夹中的Configuration.cs文件中有上面的代码 当我在程序包管理器控制台中运行“Update-Database -Verbose”时,我收到一个错误,即filePath为null。 如果我手动设置filePath与文件的绝对URL: string filePath = “C:/Users/User1/My Documents/Visual Studio […]

使用现有表进行代码优先迁移

在我的模型中,我有导航属性语言: public class IntegratorDescription : BaseContract { [Key, Column(TypeName = “bigint”), DataMember] public long Id { get; set; } [DataMember, Column(TypeName = “bigint”), ForeignKey(“Language”)] public long LangId { get; set; } [DataMember] public string CompanyShortInfo { get; set; } [DataMember, Column(TypeName = “ntext”)] public string CompanyInfo { get; set; } public virtual Models.Language Language { […]

代码优先迁移 – 如何显示待定模型更改?

我正在使用代码首次迁移。 在构建新的迁移之前,有没有办法在包管理器控制台中显示挂起的模型更改?

代码首先创建表

我正在学习本教程,并尝试在userprofile表中添加一些新列。 我试图创建一个新表。 public class UsersContext : DbContext { public UsersContext() : base(“DefaultConnection”) { } public DbSet UserProfiles { get; set; } public DbSet TestTabel { get; set; } } [Table(“UserProfile”)] public class UserProfile { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int UserId { get; set; } public string UserName { get; set; } public string Mobile { get; […]