我安装了MS SQL Server 2008 R2,当我尝试在EDMX文件下从数据库更新模型时,我遇到了这个错误.
无法加载文件或程序集Microsoft.SqlServer.management.sdk.sfc版本11.0.0.0
我正在使用EF5 beta1,而我之前能够运行"更新数据库".现在我关闭了Visual Studio,我无法让它运行.我收到以下错误:
术语"更新 - 数据库"未被识别为cmdlet,函数,脚本文件或可操作程序的名称.检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试.在行:1 char:16 + Update-Database <<<< -verbose + CategoryInfo:ObjectNotFound:(Update-Database:String)[],CommandNotFoundException + FullyQualifiedErrorId:CommandNotFoundException
我试图重新安装EF5b1并且虽然成功(已安装),但"更新数据库"仍然无效.
谁能帮忙???
entity-framework ef-code-first ef-migrations entity-framework-5
当我从Package Manager控制台运行update-database但不知道如何操作时,我想在我的Entity Framework数据库配置类中调试Seed()方法.我想与其他人分享解决方案,以防他们遇到同样的问题.
我重命名了几个实体及其导航属性,并在EF 5中生成了一个新的迁移.通常在EF迁移中重命名,默认情况下它会删除对象并重新创建它们.这不是我想要的,所以我几乎不得不从头开始构建迁移文件.
public override void Up()
{
DropForeignKey("dbo.ReportSectionGroups", "Report_Id", "dbo.Reports");
DropForeignKey("dbo.ReportSections", "Group_Id", "dbo.ReportSectionGroups");
DropForeignKey("dbo.Editables", "Section_Id", "dbo.ReportSections");
DropIndex("dbo.ReportSectionGroups", new[] { "Report_Id" });
DropIndex("dbo.ReportSections", new[] { "Group_Id" });
DropIndex("dbo.Editables", new[] { "Section_Id" });
RenameTable("dbo.ReportSections", "dbo.ReportPages");
RenameTable("dbo.ReportSectionGroups", "dbo.ReportSections");
RenameColumn("dbo.ReportPages", "Group_Id", "Section_Id");
AddForeignKey("dbo.ReportSections", "Report_Id", "dbo.Reports", "Id");
AddForeignKey("dbo.ReportPages", "Section_Id", "dbo.ReportSections", "Id");
AddForeignKey("dbo.Editables", "Page_Id", "dbo.ReportPages", "Id");
CreateIndex("dbo.ReportSections", "Report_Id");
CreateIndex("dbo.ReportPages", "Section_Id");
CreateIndex("dbo.Editables", "Page_Id");
}
public override void Down()
{
DropIndex("dbo.Editables", "Page_Id");
DropIndex("dbo.ReportPages", "Section_Id");
DropIndex("dbo.ReportSections", "Report_Id");
DropForeignKey("dbo.Editables", "Page_Id", "dbo.ReportPages");
DropForeignKey("dbo.ReportPages", "Section_Id", "dbo.ReportSections");
DropForeignKey("dbo.ReportSections", "Report_Id", "dbo.Reports");
RenameColumn("dbo.ReportPages", "Section_Id", "Group_Id"); …Run Code Online (Sandbox Code Playgroud) c# sql-server entity-framework ef-migrations entity-framework-5
我已使用该Add-Migration命令创建了迁移,但我想更改该迁移的名称.如何撤消迁移命令,以便我可以使用新的所需名称重新生成它?
是否只是删除生成的文件,或者这可能是一个坏主意?
使用带有通用存储库模式的EF5和ninject用于依赖性损害并在尝试使用存储过程与我的edmx将实体更新到数据库时遇到问题.
我在DbContextRepository.cs中的更新是:
public override void Update(T entity)
{
if (entity == null)
throw new ArgumentException("Cannot add a null entity.");
var entry = _context.Entry<T>(entity);
if (entry.State == EntityState.Detached)
{
_context.Set<T>().Attach(entity);
entry.State = EntityState.Modified;
}
}
Run Code Online (Sandbox Code Playgroud)
从我的AddressService.cs回到我的存储库我有:
public int Save(vw_address address)
{
if (address.address_pk == 0)
{
_repo.Insert(address);
}
else
{
_repo.Update(address);
}
_repo.SaveChanges();
return address.address_pk;
}
Run Code Online (Sandbox Code Playgroud)
当它命中Attach和EntityState.Modified时,它会发出错误:
ObjectStateManager中已存在具有相同键的对象.ObjectStateManager无法使用相同的键跟踪多个对象.
我已经查看了堆栈和互联网上的许多建议,但没有提出解决它的任何建议.任何工作都将受到赞赏.
谢谢!
c# entity-framework ninject repository-pattern entity-framework-5
我需要在我的数据库中有一列由数据库计算为(行数之和) - (行数b).我正在使用代码优先模型来创建我的数据库.
这就是我的意思:
public class Income {
[Key]
public int UserID { get; set; }
public double inSum { get; set; }
}
public class Outcome {
[Key]
public int UserID { get; set; }
public double outSum { get; set; }
}
public class FirstTable {
[Key]
public int UserID { get; set; }
public double Sum { get; set; }
// This needs to be calculated by DB as
// ( Select sum(inSum) FROM Income WHERE UserID …Run Code Online (Sandbox Code Playgroud) c# sql-server calculated-columns ef-code-first entity-framework-5
有没有办法在实体框架中找出我的实体上下文中是否有未保存的更改?
entity-framework entity-framework-4 entity-framework-5 entity-framework-6
我正在使用Entity Framework 5(DBContext),我正在尝试找到深度复制实体的最佳方法(即复制实体和所有相关对象),然后将新实体保存在数据库中.我怎样才能做到这一点?我已经研究过使用扩展方法,CloneHelper但我不确定它是否适用DBContext.
我使用EF 5.0 Code First Migrations成功运行了默认的ASP.NET MVC 4模板.但是,当我更新模型属性名称时,EF 5.0将删除相应的表列数据.
是否可以以某种方式重命名表列而不以自动方式删除数据?