1

I have a class like below.

public abstract class Employee
{
   public abstract string EmployeeType {get;}
}

public class Engineer: Employee
{
   public override string EmployeeType 
   { 
      get
      {
         return "engineer";
      } 
   }    
}

I have another class which has a List of Employees, that can have different types of employees (Engineer, Manager etc.). This class serializes well into my Mongo database. However, for deserializing, how do I specify the deseralizer to deserialize the Employee record to either Engineer or Manager objects based on the EmployeeType string. How do I specify this to the MongoDB deserializer (for database layer) and JSON.NET deserializer (for middle tier)?

1 Answer 1

1

The best way to do this is using mongo type discriminators. Here's a good article about it:

http://mycodeonline.com/peterkneale/blog/mongo-type-discriminators

Hope it helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.