caa
caa

Reputation: 441

Is there a way of avoiding 2 repository objects for the same database table?

Im currently working in a team that uses EF as the ORM of choice.

We have a common project that contains many EDMX files. The reason for this is to keep the EDMX files small and manageable while also allowing them to focus on a conceptual set of tables on the database.

Eg

These all point to a different set of tables on the same db.

I now need to add the user table to the Trade.edmx file. Since the user table is already in the user.edmx file, this creates the same User type twice under a different namespace which means I would need 2 UserRepository objects.

Is there a way of avoiding 2 repository objects for the same table?

Any suggestions would be greatly appreciated

Upvotes: 0

Views: 113

Answers (1)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364279

If you are using POCO generator you can update template for Trades.edmx to not generate new User class and its context template to use User class from Users namespace. EF matches POCO classes with entities in designer only by the class name (namespace is omitted) so it will work.

The disadvantage is that you have User entity in two mapping files and you must update it in both files or your application throw exception at runtime.

The reason for this problem is your architecture - at the beginning you wanted separated models but know you want to combine entities from different models. Those are contradicting requirements. Either use separated model where Trade knows only userID without any navigation property (like if it is defined in another database) or move all entities to single EDMX to support your new requirements.

Upvotes: 1

Related Questions