This project is read-only.

New inheritance mapping question.

Sep 9, 2015 at 11:00 AM
Hello! How I can map this inheritance:
 public class DataObject
 {
     public Guid Guid { get; set; }
     public string Name { get; set; }
     public string DisplayName { get; set; }
     public string Description { get; set; }
     public string DistinguishedName { get; set; }
     public string CommonName { get; set; }
     public DateTime WhenCreated { get; set; }
     public DateTime WhenChanged { get; set; }
    }

public class UserHeader : DataObject
{
     public string Sid { get; set; }
     public string FirstName { get; set; }
     public string LastName { get; set; }
     public string MiddleName { get; set; }
}

public class User : UserHeader
{
    public ICollection<GroupHeader> Groups { get; set; }
}
User and UserHeader classes should have "User" objectClass value, but for new inheritance logic this classes should have different objectClass.
Sep 13, 2015 at 10:39 PM
So if UserHeader and User both have the "User" object class, why are they separate .Net classes? From a data model perspective, there has to be something different about their storage to justify creating two classes.
Sep 14, 2015 at 8:23 AM
In this case, I prevent to load "Groups" and other properties, that can store large data. Header is common information about user, and User is full information with picture, groups, etc.
Sep 16, 2015 at 4:00 AM
Is there a reason you can't use a select to limit the properties returned?
Sep 16, 2015 at 10:42 AM
I can not use anonymous objects, that generated by "Select" method, because I should provide classes to other methods (to OData Web Api infrastructure).
Sep 16, 2015 at 8:02 PM
I don't think you need to use an anonymous object. You should be able to project your User object into an unmapped UserHeader object.

If you don't want to perform the select on the server, you should be able to perform it on the client side and wrap it in a client side service / repository for standardization. I'm not as familiar with Web API's OData capabilities, but it seems from this article that it is possible: Web API tutorial
Sep 17, 2015 at 7:34 PM
You know, I don't know why I didn't think of it before, but if you don't want to change your mapping structure too much, you can just introduce one extra object to share code and create two mappings for the different objects:
 public class DataObject //leave this unmapped
 {
     public Guid Guid { get; set; }
     public string Name { get; set; }
     public string DisplayName { get; set; }
     public string Description { get; set; }
     public string DistinguishedName { get; set; }
     public string CommonName { get; set; }
     public DateTime WhenCreated { get; set; }
     public DateTime WhenChanged { get; set; }
 }

public class UserBase : DataObject //leave this unmapped
{
     public string Sid { get; set; }
     public string FirstName { get; set; }
     public string LastName { get; set; }
     public string MiddleName { get; set; }
}

public class UserHeader : UserBase //map this class
{
}

public class User : UserBase //map this class
{
    public ICollection<GroupHeader> Groups { get; set; }
}
Sep 17, 2015 at 8:07 PM
An interesting solution, but I share data classes between different projects and pass it to OData, that generate schema definition, so I should avoid creating many empty objects.
UserHeader class is used in collection (to load large collection and search data), User class is used to provide full information about user, such as image, groups and additional information from another databases. I pass IQueryable from Query<UserHeader>() to OData querying infrastructure, so I should map UserHeader explicitly.