Calling base properties from a [Column] property accessor in a derived class in DLinq


Why does the following not work ...

public abstract class DomainObject<TId> {
TId id;
protected TId IdBase {
get { return this.id; }
set { this.id = value; }
}
}
[Table]
public class Topic
: DomainObject<int> {

[Column(Id = true, AutoGen = true)]
public int Id {
get { return base.IdBase; }
set { base.IdBase = value; }
}
}

... it fails with a TargetInvokationException:

at System.RuntimeMethodHandle._InvokeConstructor(Object[] args, SignatureStruct& signature, IntPtr declaringType)
at System.RuntimeMethodHandle.InvokeConstructor(Object[] args, SignatureStruct signature, RuntimeTypeHandle declaringType)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
at System.Data.DLinq.AttributedMetaDataMember.CreateAccessor(Type accessorType, Object[] args)
at System.Data.DLinq.AttributedMetaDataMember.MakeMemberAccessor(Type accessorType, MemberInfo mi)
at System.Data.DLinq.AttributedMetaDataMember.MakeMemberAccessor(MemberInfo mi)
at System.Data.DLinq.AttributedMetaDataMember..ctor(MetaType metaType, MemberInfo mi, Int32 ordinal)
at System.Data.DLinq.AttributedMetaType.InitDataMembers()
at System.Data.DLinq.AttributedMetaType.GetPersistentDataMembers()
at System.Data.DLinq.AttributedRootType.Validate()
at System.Data.DLinq.AttributedRootType..ctor(AttributedMetaModel model, AttributedMetaTable table, Type type)
at System.Data.DLinq.AttributedMetaTable..ctor(AttributedMetaModel model, TableAttribute attr, Type rowType)
at System.Data.DLinq.AttributedMetaModel.GetTable(Type rowType)
at System.Data.DLinq.DataContext.GetTable(Type type)
at System.Data.DLinq.DataContext.GetTable[T]()
[...]

...yet, if 'IdBase' is public, it works:

public abstract class DomainObject<TId> {
TId id;
// this property seems to have to be public, even though it is not part of
// the data model exposed by the dervied type
public TId IdBase {
get { return this.id; }
set { this.id = value; }
}
}

Thanks.



Answer this question

Calling base properties from a [Column] property accessor in a derived class in DLinq

  • Liza

    Unfortunately, I've confirmed that this is a bug. There is no terrific workaround - I see your options as:

    • Declare your property as public as you mentioned above
    • Remove the property, and use a protected field

    public abstract class DomainObject<TId> {
    protected TId IdBase;
    }

    Neither are great options I'm afraid.



  • vital

    Thanks for the quick response. Its good to know this should work.


  • Calling base properties from a [Column] property accessor in a derived class in DLinq