3
Vote

Model's properties are not generated when inherited from another class

description

If our model inherited from another class (for example : InvoiceViewModel : Invoice) the code generator does not generate any properties of the parent class.
As I checked the following function the problem comes from "prop.IsReadable()" where it returns False for all parent class's properties:

List<ModelProperty> GetEligibleProperties(EnvDTE.CodeType typeInfo, bool includeUnbindableProperties) {
List<ModelProperty> results = new List<ModelProperty>();
if (typeInfo != null) {
    foreach (var prop in typeInfo.VisibleMembers().OfType<EnvDTE.CodeProperty>()) {
        if (prop.IsReadable() && !prop.HasIndexParameters() && (includeUnbindableProperties || IsBindableType(prop.Type))) {
            results.Add(new ModelProperty {
                Name = prop.Name,
                ValueExpression = "Model." + prop.Name,
                Type = prop.Type,
                IsPrimaryKey = Model.PrimaryKeyName == prop.Name,
                IsForeignKey = ParentRelations.Any(x => x.RelationProperty == prop),
                IsReadOnly = false//!prop.IsWriteable()
            });
        }
    }
}

return results;
}

comments

AndreyTS wrote Mar 7, 2012 at 6:10 AM

I also run into this issue, where is IsReadable defined? MSDN doesn't show it among properties of EnvDTE.CodeProperty interface...

AndreyTS wrote Mar 7, 2012 at 6:51 AM

As a workaround — I created custom templates for Views and used there «prop.Getter != null && prop.Getter.Access == EnvDTE.vsCMAccess.vsCMAccessPublic» instead of «prop.IsReadable()». That worked.

leblanc wrote Feb 24 at 2:37 PM

thanks for the work around