Bug when using inheritance?

Aug 1, 2012 at 9:15 PM

Hi,

first off: I like this component very much, it's pretty easy to use and works just fine. However, I think I have discovered a bug when using inheritance in the entity model.

I have an enity called User and an entity called UserGroup. I also have an abstract bass class/entity called Principal. Both User and UserGroup are derived from that base class. So far, this is not a problem.

Now, my Principal entity has an m2m relation to another entity called Permission. The navigation property is called Permissions. So I followed the instructions, created a link table called PrincipalPermission and added link table views to both the Principal and the Permission class. I also specified the association between Principal and Permission in the domain service's meta data configuration class.

At this point, I can no longer compile because the generated client code is just wrong. The problem seems to be that M2M4RIA generates the "Permissions" property (which returns the collection of Permission objects) not only for the Principal class, but also for User and UserGroup - although they inherit it from Principal anyway. The same applies to the generated private method "AddPrincipalPermission". Although it already exists for Principal, M2M4RIA generates it again for User and UserGroup. In the case of User,  within the method there are two lines of code:

var newLinkTableEntity=new PrincipalPermission;
PrincipalPermission.AttachPermissionToUser(...)

And that "AttachPermissionToUser" method does not exist (and it's not needed anyway).  That's actually the reason why compilation fails. Same happens to UserGroup.

The expected behavior would be that M2M4RIA doesn't generate anything related to this association neither for User nor UserGroup since the association only exists between Principal and Permission and User/UserGroup inherit it from Principal. I guess, this should be quite easy to fix. You just need to check if the association you're generating is defined in a base class of the current type and if so, ignore it.

Would be great if you could have a look at this issue and provide an update.

Btw. I noticed that the latest version of RiaServices.M2M on NuGet (2.0.4594.18952) has a dependency on a version of RiaServices.M2M.LinkTable with the same version number, but that version isn't available on NuGet (latest version is 2.0.4546.27447).

Thanks in advance,

Ben

 

 

Aug 2, 2012 at 9:58 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.