views:

21

answers:

2

hi there, i've been working with fluent nhibernate for a couple of months and i think it's a very flexible tool (even if 'tool' is maybe incorrect term) :)

i've to work on a new project and i'm still considering using fluent nhibernate solution to map my db on a repository layer. The matter is that, for some reason i really don't understand, the db is not 'standard' structured.

I mean that tables are not referenced by foreign key, but i do know that there are cases where :

TABLE X: column A type nvarchar TABLE Y: column A type int

X is the table that contains datas (in the form of codes), while Y is the table that contains X.A description.

As if it's an absurd situation!!! but i can't do anything on the db. So the question is: can i map these tables in fluent nhibernate, referencing them even if columns are of different types?

thx in advance

+2  A: 

No, a foreign key with completely different data types is not supported by NHibernate.

Now, considering this is a new project, what you need to do is fix the database.

Diego Mijelshon
A: 

Yes and no. You can map the tables but not the relationships. This would give you an anemic domain model and repository methods to retrieve related objects, i.e. accessing Orders from a GetOrdersForCustomer() method rather than a Customer.Orders collection.

Another possibility would be to create custom user types for these properties, such as IntStoredAsString. I have only used custom types for properties so I'm not sure how well they work as foreign keys.

Jamie Ide