[英]SubSonic edit class problem
I'm having a very odd issue with SubSonic where when I edit a class the database isn't being updated, even when I delete it and regenerate it. 我在SubSonic中遇到一个非常奇怪的问题,即当我编辑一个类时,即使删除并重新生成它,数据库也不会被更新。
Example: Simple class 示例:简单类
public class Customer {
public Guid Id { get; set; }
public string Description { get; set; }
}
Customer c = new Customer() { Id = Guid.NewGuid(), Description = "Toaster" };
var repo = new SimpleRepository("CustomerTest",
SimpleRepositoryOptions.RunMigrations);
repo.Add(c);
If I run this code it works perfectly, creates a table "Customer" and inserts the row for the toaster. 如果我运行此代码,它将运行完美,创建一个“ Customer”表,并为烤面包机插入一行。 However if I decide to change my Customer class to:
但是,如果我决定将客户类别更改为:
public class Customer {
public Guid Id { get; set; }
public string Description { get; set; }
public int Cost { get; set;}
}
And run the same code adding a value for the Cost property the database table remains "Id, Description". 并运行相同的代码,为数据库表的Cost属性添加一个值,该表仍为“ Id,描述”。 If I create a totally new class and past in the Customer fields it will create the table correctly the first time and again any changes dont appear to work.
如果我创建了一个全新的类并在“客户”字段中过去,它将在第一次正确创建表,并且所有更改似乎都无法正常工作。
Any help? 有什么帮助吗?
First off all, you should try to figure out if subsonic detects your class definition changes properly. 首先,您应该尝试确定subsonic是否正确检测到您的类定义更改。
This code should give you a overview of the statements subsonic want's to execute. 此代码应为您提供亚音速想要执行的语句的概述。
var migrator=new SubSonic.Schema.Migrator(Assembly.GetExecutingAssembly()); var provider=ProviderFactory.GetProvider("CustomerTest"); string[] commands=migrator.MigrateFromModel<Customer>(provider);
commands should contain all changes subsonic wants to make to your database. 命令应包含subsonic希望对数据库进行的所有更改。 You can execute these commands by yourself with: BatchQuery query = new BatchQuery(provider);
您可以使用以下命令自己执行这些命令:BatchQuery query = new BatchQuery(provider); foreach(var s in commands) query.QueueForTransaction(new QueryCommand(s.Trim(), provider));
foreach(命令中的var)query.QueueForTransaction(new QueryCommand(s.Trim(),provider));
//pop the transaction query.ExecuteTransaction();
(code taken from http://subsonicproject.com/docs/3.0_Migrations ). (代码取自http://subsonicproject.com/docs/3.0_Migrations )。
That said, I suppose commands will be empty in your case. 就是说,我想您的情况下命令将为空。 In that case that could be caused by a statement that is not implemented by the provider you are using (SqlServer/MySQL/SQLite/Oracle).
在这种情况下,可能是由于您使用的提供程序未实现的语句引起的(SqlServer / MySQL / SQLite / Oracle)。 Maybe you should download the SubSonic source and step into the
migrator.MigrateFromModel(...)
method to see what happens. 也许您应该下载SubSonic源码并进入
migrator.MigrateFromModel(...)
方法以查看会发生什么。
Another possible cause (if you use MySQL) could be that your information schema is not up to date. 另一个可能的原因(如果使用MySQL)可能是您的信息架构不是最新的。 I encountered this problem a while ago.
我前一段时间遇到了这个问题。 After changing my database and regenerating the DAL with SubSonic 2, my generated code didn't change.
更改数据库并使用SubSonic 2重新生成DAL之后,生成的代码未更改。
I figured out that the mysql information schema (and subsonic does queries on the information schema) hadn't changed yet. 我发现mysql信息架构(和subsonic会对信息架构进行查询)尚未更改。 I solved this by executing
FLUSH TABLES
which caused the information scheme to reload. 我通过执行
FLUSH TABLES
解决了此问题,该FLUSH TABLES
导致信息方案重新加载。 I don't know if that's a bug in mysql or desired behaviour but you should try FLUSH TABLES first. 我不知道这是mysql中的错误还是所需的行为,但您应该首先尝试使用FLUSH TABLES。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.