To get all the functionality of the BusinessFramework entity should be derived from EntityBase, for example

[NotifyPropertyChanged]
public class Customer : EntityBase<Entity>
{
    public Customer()
    {
        Addresses = new ObservableCollection<Address>();
    }

    public string Name { get; set; }
    public string TIN { get; set; }
    public ObservableCollection<Address> Addresses { get; private set; }
}
If you need inheritance hierarchy for other purposes, you can register EntityExtensions in your own base class or entity class.

[NotifyPropertyChanged]
public class MyEntityBase<T>
    where T : MyEntityBase<T>
{
    private IEntityExtensions<T> _extensions;
    public IEntityExtensions<T> Extensions
    {
        get
        {
            if (_extensions == null)
                _extensions = EntityExtensions.RegisterObject(this).GetTypeSafe<T>();

            return _extensions;
        }
    }
}
Or you can even register extensions for existing types:

public void MyMethod()
{
    var customer = new Customer();
    var ex = EntityExtensions.RegisterTypedObject(customer);

    ex.CreateValidationRule(en => en.Name == "abc")
        .WithMessage("info")
        .WithSeverity(BrokenRuleSeverity.Info)
        .Enable();
}

Last edited Mar 13, 2011 at 10:40 PM by michaelmac, version 11

Comments

No comments yet.