0

I want to Validate (IDataErrorInfo) of my properties which are generated through the Telerik OpenAccess Mapper.

Like this.

public partial class Etage
{
    private long _version;
    public virtual long Version 
    { 
        get
        {
            return this._version;
        }
        set
        {
            this._version = value;
        }
    }...

Now i want to override the property "Version" in my second class Etage (also partial) like this.

public partial class Etage : IComparable
{

    public override long Version
    {
        get { return _version; }
        set { _version = value+200; }
    }

    // Some Validation in the Setter later...
    public override string ToString()
    {
        return String.Format("{0}", Version);
    }
}

Then i get the following Error:

Ambiguity between 'Inventar.Model.Etage.Version' and 'Inventar.Model.Etage.Version'

Dean Kuga
  • 11,878
  • 8
  • 54
  • 108
slopsucker
  • 51
  • 1
  • 8
  • As far as I know you can't override a method declared on a partial class inside a partial part of that class - only on a subclass – Charleh Jun 22 '12 at 21:35
  • See here: http://stackoverflow.com/questions/247800/override-default-constructor-of-partial-class-with-another-partial-class – Charleh Jun 22 '12 at 21:37
  • I tried a Subclass, but than i cant work with the Mapper... if i want to insert a new "Subetage" than there is no Mapping for this Class.. and if i map it, it will be generated new... – slopsucker Jun 22 '12 at 21:40
  • You could use a templated class - e.g. MappedClass and then use Etage : MappedClass and SubEtage : MappedClass then in MappedClass you might be able to get it to work. I did this with AutoMapper and it worked a charm – Charleh Jun 22 '12 at 21:44
  • Never heared from templated classes, i will try to teach it myself and hope getting it work. I never worked with that bevore ... but thanks for the tip :) Have you maybe a example from your Code for Override with Generic Classes? – slopsucker Jun 22 '12 at 21:49
  • I'm a telerik customer so I will download the SDK and have a look for you if I can do it tomorrow (bed time soon here!) – Charleh Jun 22 '12 at 21:51

3 Answers3

1

There isn't a way to override properties in a partial class, you need to do it in a derived one. However using a derived class might not help, given that the OpenAccess context will retrieve instances from the base class and there isn't an easy way of converting those to your new types.

What you can do is add a property with a different name (in the partial class), that does the neccessary calculations. This however will mean that you will have both exposed on the model. In order to fix that you can change the access modifier of the generated property trough the visual designer. Just find the property and change it's access modifier in the properties pane to something different from public.

sovanesyan
  • 1,098
  • 1
  • 8
  • 15
0

This might work:

public partial class SubEtage : Etage
{

    public override string Beschreibung
    {
        get { return base.Beschreibung; }
        set { base.Beschreibung = value + "GEHT"; }
    }

    public override string ToString()
    {
        return String.Format("{0}", Beschreibung);
    }
}

And check out the links:

http://www.telerik.com/help/openaccess-orm/openaccess-tasks-howto-single-class-single-table.html

Charleh
  • 13,749
  • 3
  • 37
  • 57
  • This may be absolutely useless to you though, I will download the telerik mapping SDK at some point - it looks useful – Charleh Jun 22 '12 at 21:53
  • Ok, this would be great if you could try it with the Telerik SDK, never seen a Method for creating maps manually (like OpenAccess.CreateMap()). I could send you my Projekt if you want so everything is done already except the override. Here is bed time too.. :) Big thanks for your help already! – slopsucker Jun 22 '12 at 21:57
  • Yeah send me it if you want - I've got express on my home machine I'll see if I can open it on that, otherwise I can open up my work laptop – Charleh Jun 22 '12 at 22:00
  • Hi dude, I've downloaded it - will have a look at Telerik ORM now – Charleh Jun 23 '12 at 10:35
  • Ok thanks! Hope there is a solution with this ORM, liked it so far :D – slopsucker Jun 23 '12 at 13:09
  • Found some info on the Telerik site: http://www.telerik.com/help/openaccess-orm/openaccess-application-scenarios-inheritance.html – Charleh Jun 23 '12 at 13:48
  • And here: http://www.telerik.com/help/openaccess-orm/openaccess-tasks-howto-single-class-single-table.html - looks like inheritance will work, you can override the partial classes in the subclass as long as you set it up ok in the OpenAccess mapper - I've added some info to my post – Charleh Jun 23 '12 at 13:51
  • I tried your Edited Example above, but cant Map my SubClass... find no possability in the Q2 2012 SDK. Getting the following Error: Argument 1: cannot convert from 'System.Linq.IQueryable' to 'System.Collections.Generic.List' – slopsucker Jun 23 '12 at 14:31
0

You can control how the OpenAccess code generator creates its code by modifying the TT templates that it uses. Here are some links that should get you on the right track:

Alexander
  • 2,320
  • 2
  • 25
  • 33