views:

54

answers:

1

I havea simple EF Model with a Test entity and I want to make use of partial classes to add validation like this:

namespace WebApp.Model
{
    using WebApp.BusinessRules;
    using WebApp.BusinessRules.Rules;
    using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;

    [HasSelfValidation]
    public partial class Test : BusinessObject
    {
        public Test()
        {
            AddRule(new ValidateRequired("Title"));
        }
    }
}

But I get this error:

Partial declarations of 'Model.Test' must not specify different base classes.

I understand the error but how can I use EF4 Models and still have access to all my business validation goodness?

BusinessObject has all the validation and stuff, so if I can get them working happily together, I'm all done. Hope someone can help.

Richard

+1  A: 

With your current setup (using default EF EntityObjects) there is no way that you can get your entities inherit from BusinessObject. Instead of inheritance you can use Composition though, which means each partial class would have a field of BusinessObject type.

If you want to stick to your inheritance, then you should use EF 4 POCO Entitie instead and then have your POCOs to inherit from BusinessObject.

Morteza Manavi