I am sure this is not possible, but here it goes.
I have a custom class in C # called Person, which has several properties like Age, Height, etc.
Then I create a new Employee class that inherits from Person, but I don't add any other Employee properties yet. Thus, his basically just a man is still, except for his called Employee.
Now say that I have an instance of Person called SomePerson. How can I create a new instance of Employee that has all the values ββthat it inherits from Person and set them to SomePerson. Like casting from Man to Worker. But without me, you need to manually specify each property that needs to be set.
Something like..
Employee NewEmployee = (Employee)SomePerson;
But, of course, you get the error message "Unable to convert Person to Employee", etc.
Is AutoMapper the only practical solution for such actions if you say that the object had 300 properties?
UPDATE:
Auto-Mapper doesn't seem to process my objects.
Employee SomeEmployee = EmployeeRepository.GetEmployee(SomeEmployeeID); // Populate the ViewModel with the Person fetched from the db, ready for editing.. VMEmployee EmployeeToEdit = Mapper.Map<Employee, VMEmployee>(SomeEmployee); // ViewModel based on Employee with Validation applied.. [MetadataType(typeof(Employee_Validation))] public class VMEmployee : Employee { // Absolutely nothing here }
where "Employee" is automatically generated LINQ to SQL ..
inheritance c #
Aaron
source share