开发者

If use the ActiveRecord,generate models each I modify the database structure? [closed]

开发者 https://www.devze.com 2023-01-23 23:17 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

if i开发者_运维百科t's like this,i think it's troubles.


What is more trouble, a compile time error because you renamed a column or a run time error "Column xyz does not exist".

If you want to change the generated classes by yourself and are worried about your changes being overwritten. There are three ways to make modifications to the generated DAL.

  1. SubSonic classes are partial.

    If you create another class within the same namespace you can add properties/methods and override members (from the base class).

  2. Modify the templates.

    Depending on the SubSonic version (2 or 3) there are different approches how to generate the DAL. But they both share a similar aspx like syntax (2 = custom, 3 = T4 Engine)

  3. Inherit from the classes.

You can create your own classes that inherit from the generated ones. (I would not suggest to do that if you want to use SubSonic2's xyzCollection.

Update: The T4 (*.tt) templates are executed only when you change the file or right click a tt file and choose "Run Custom Tool". For SubSonic, after a Schema changed you have to select "Run custom tool" for every tt file you want to update (ActiveRecord.tt, Structs.tt, etc.). However, T4 is a standalone tool that can be easily be integrated in your build process:

http://broloco.blogspot.com/2008/11/using-t4-command-line-parameters.html


If you are using Subsonic, the model is recreated each time the database is modified (automatically if you are using the build provider or manually if you are using Subsonic.exe to generate classes).

What is the problem with the fact that the model is regenerated?

0

精彩评论

暂无评论...
验证码 换一张
取 消