Hi,

Is it possible to rename an Entity? If so what would the procedure. Of course I will like to preserve data and schema integrity.

Thank you,

Richard

asked Jun 16 '14 at 15:53

rasxte's gravatar image

rasxte
20161617


One Answer:

Hello Richard.

Yes, it is possible. You can use RecycledAttribute for new Entity and specify old full name of Entity.

For example, you have old entity


namespace MyApplication.Model
{
  [HierarchyRoot]
  public class SomeOldEntity
  {
   // Fields specification
  }
}

And you rename SomeOldEntity with SomeNewEntity

namespace MyApplication.Model
{
  [HierarchyRoot]
  [Recycled("MyApplication.Model.SomeOldEntity")]
  public class SomeRenamedEntity
  {
   // Fields specification
  }
}

It is simplest way to rename some enity. And you should build domain in Preform or PerformeSafely upgrade mode.

Another one way to change model its implement your own Upgrade handler. Upgrade handler is class responsible for upgrade of persistent classes from one assembly. It must be inherited from UpgradeHandler or implement IUpgradeHandler interface, it also must have a parameterless constructor. Each assembly with persistent model should contain exactly one upgrade handler class, it will be automatically found when schema is being upgraded. UpgradeHandler class contains a set of methods and properties that can be overridden for customizing schema upgrade process. For example,


public class Upgrader : UpgradeHandler
{
  protected override void AddUpgradeHints(Xtensive.Collections.ISet<upgradehint> hints)
  {
    //rename entity
    hints.Add(new RenameTypeHint("MyProduct.Model.Customer", typeof (Person)));
    //rename field of entity
    hints.Add(new RenameFieldHint(typeof (Person), "Name", "FullName"));
  }
}

You should read documentation about upgrade for DO-4.6 and for DO-5.0 Beta.

answered Jun 17 '14 at 00:01

Alexey%20Kulakov's gravatar image

Alexey Kulakov
77225

Hi Alexey,

I didn't know this functionality existed...

I will give it a try.

Thank you,

Richard

(Jun 17 '14 at 21:24) rasxte rasxte's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×9
×1

Asked: Jun 16 '14 at 15:53

Seen: 3,523 times

Last updated: Jun 17 '14 at 21:24

powered by OSQA