Closed phoenix172 closed 6 years ago
Mapping properties from inherited class should be supported. Could you show code of your classes?
Child Entity
Person Entity
Entity
Child Model
Model Base
When I try to generate mapping from Child Entity to Child Model, I get this(ignore the recursion code - this is just an illustration):
And when I do it the other way round - Child Model to Child Entity, this is the result:
Notice that in the first case there isn't an Id column mapping, while in the second there is. Maybe I am doing something wrong?
Are these classes in the same assembly?
Yes, they are. Just different namespaces.
Ok, I've just found the culprit, ModelBase.Id
has setter with internal
modifier. I need to handle this case. but it can take a while. I have no idea how to check if element with internal modifier is accessible in given context.
I've found code that check if two types are from different assemblies but this requires a lot of changes because we need to pass context of code generation https://github.com/dotnet/roslyn/blob/master/src/Workspaces/Core/Portable/Shared/Extensions/ISymbolExtensions_Accessibility.cs
@phoenix172 Could you test this version https://ci.appveyor.com/api/buildjobs/v2ooime65b205pff/artifacts/MappingGenerator%2FMappingGenerator%2FMappingGenerator.Vsix%2Fbin%2FRelease%2FMappingGenerator.vsix and tell me if all mappings works correctly?
Confirmed working. Nice job and thank you :)
I guess you would want to close this with a commit :)
Oh just found a new problem that I am not sure was present with the old version.
The Generate Mapping option does not appear when the cursor is at the end of the method name.
If this is not just the new version, I can open a separate issue.
This problem is not related with the original issue but there is no need to create another ticket. I will check that tomorrow.
@phoenix172 would you be so kind to test the new version? https://ci.appveyor.com/api/buildjobs/mnxgommposnkhw7q/artifacts/MappingGenerator%2FMappingGenerator%2FMappingGenerator.Vsix%2Fbin%2FRelease%2FMappingGenerator.vsix
Works great :)
Thanks for testing. Fix merged into develop, should be released in few days.
I have a class ChildModel inheriting from ModelBase which contains an Id property and a class Child inheriting from Entity which also contains an Id property of the same type. When I try to generate a mapping from Child to ChildModel all properties are mapped except the Id property.
It is not difficult to add it manually in my case but if there were more properties it would become a bit annoying. I don't know if this is intended behavior or just something you haven't thought about.
UPDATE: I just noticed something else. Curiously enough, when I generate code for the opposite mapping i.e ChildModel to Child, I do get mapping code for the Id property.