Many to Many on a base type

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
bug_me_not
Posts: 5
Joined: Sat 20 Aug 2011 09:14

Many to Many on a base type

Post by bug_me_not » Tue 13 Nov 2012 06:35

Hi,
I am testing the nhibernate trail version.
I am planning a system with 3 different type of users.
AdvertizerUser
PublisherUser
EmployeeUser

they are all inheriting from BaseUser(abstract, table per concrete type)

I want BaseUser to have Many to Many relations with Role table so each user has X amount of roles.
So AdvertizerUser,EmployeeUser,PublisherUser will have Roles property inside.

When I do manual development of fluent nhibernate, this is no-brainer.
I just set the property
public virtual List<Role> Roles { get; set; }
Map(x => x.Roles).CustomType(typeof(UserRoleCustomType)).Column("roles");
and it will be divided in to the three *User tables.

So, what is the way to create many to many relation in base type for all children.
Thanks

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Many to Many on a base type

Post by Shalex » Tue 13 Nov 2012 14:58

We have just sent a test project to your e-mail address.
Key points:
1) the associations should be set between the child classes and Role. No sense to set an association between BaseUser (abstract) and Role with intention to propagate the association to each child, because an Association Editor has to be available for each final association (between child classes and Role) to make necessary settings: the corresponding property in Role, the name of the intermediate "many-to-many" table in the database, etc;
2) the Roles property in the child classes on the diagram is marked as Unimplemented (creates mapping, but there is no class property);
3) the File Per Class and Generate Partial Class properties of the NHibernate template are set to True so that we can define the Roles property in the partial BaseClass.

bug_me_not
Posts: 5
Joined: Sat 20 Aug 2011 09:14

Re: Many to Many on a base type

Post by bug_me_not » Wed 14 Nov 2012 05:21

Hello and thanks,
Let me tell you what is my problem, and why I want to use it on the base.
When a user login, I want to save his BaseUser entity on the session.
than, I can just pull him from the session, no matter what type of user he is.
So I did that a lot of times manually via fluent and this architecture works perfectly for me. I would like to keep it with your great product.
Is there any work around for this.
I have seen a lot of systems that use BaseType associations.
just as an abstract example
you have alot of car types

BaseCar
-> Family
-> Track
-> Sport
-> Van

In the base type you can do many to many that fits with every car type.
for example:
List<Office> SellingOffices,
or
List<Countries> MarketInCountries

The BaseCar has powerful meaning in programming context . I assume with a great product like that you already know that (-:
Thanks

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Many to Many on a base type

Post by Shalex » Tue 20 Nov 2012 10:18

Have you received our test project on Tue Nov 13, 2012?
We have just answered you by e-mail.

Post Reply