English 中文(简体)
2. 长期老年病类问题
原标题:SubSonic edit class problem
  • 时间:2011-04-01 10:33:08
  •  标签:
  • c#
  • subsonic

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.

例:简单班

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);

如果我管理这一法典,它就会完美地发挥作用,建立一个“监管机构”表,并插入星号。 然而,如果我决定将我的客户类别改为:

public class Customer {
    public Guid Id { get; set; }
    public string Description { get; set; }
    public int Cost { get; set;}
}

数据库表仍为“Id, 说明”。 如果我在客户领域创造了一个全新的类别和历史,它将首次正确编制表格,并再次确定任何变化。

任何帮助?

最佳回答
  • First off all, you should try to figure out if subsonic detects your class definition changes properly.
    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. You can execute these commands by yourself with: BatchQuery query = new BatchQuery(provider); foreach(var s in commands) query.QueueForTransaction(new QueryCommand(s.Trim(), provider));

    //pop the transaction
    query.ExecuteTransaction();
    

    (code taken from 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). Maybe you should download the SubSonic source and step into the migrator.MigrateFromModel(...) method to see what happens.

  • Another possible cause (if you use MySQL) could be that your information schema is not up to date. I encountered this problem a while ago. After changing my database and regenerating the DAL with SubSonic 2, my generated code didn t change.
    I figured out that the mysql information schema (and subsonic does queries on the information schema) hadn t changed yet. I solved this by executing FLUSH TABLES which caused the information scheme to reload. I don t know if that s a bug in mysql or desired behaviour but you should try FLUSH TABLES first.

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签