<p>I have the situation where i use GIS software which stores the information about GIS objects into separate database table for each type/class of GIS object (road, river, building, sea, ...) and keeps the metadata table in which it stores info about the class name and its DB table.</p>

<p>Those GIS objects of different classes share some parameters, i.e. Description and ID. I'd like to represent all of these different GIS classes with one common C# class (let's call it GisObject), which is enough for what i need to do from the non-GIS part of the application which lists GIS objects of the given GIS class.</p>

<p>The problem for me is how to map those objects using NHibernate to explain to the NHibernate when creating a C# GisObject to receive and <strong>use the table name as a parameter</strong> which will be read from the meta table (it can be in two steps, i can manually fetch the table name in first step and then pass it down to the NHibernate when pulling GisObject data).</p>

<p>Has anybody dealt with this kind of situation, and can it be done at all?</p>

[{'answer_id': 51683, 'author': 'lomaxx', 'author_id': 493, 'author_profile': 'https://Stackoverflow.com/users/493', 'pm_score': 0, 'selected': False, 'text': "<p>one way you could do it is to declare an interface say IGisObject that has the common properties declared on the interface. Then implement a concrete class which maps to each table. That way they'll still be all of type IGisObject.</p>\n"}, {'answer_id': 51692, 'author': 'sirrocco', 'author_id': 5246, 'author_profile': 'https://Stackoverflow.com/users/5246', 'pm_score': 0, 'selected': False, 'text': '<p>You can have a look at what Ayende is saying here : <a href="http://www.ayende.com/Blog/archive/2007/04/24/Multi-Table-Entities-in-NHibernate.aspx" rel="nofollow noreferrer">MultiTable Entities</a>.</p>\n\n<p>But since you have separate tables , i don\'t think it will work. \nYou can also check out <a href="http://groups.google.com/group/nhusers" rel="nofollow noreferrer">nhuser group</a></p>\n'}, {'answer_id': 51829, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>It sounds like the simplest thing to do here may be to create an abstract base class with all of the common GIS members and then to inherit the other X classes that will have nothing more than the necessary NHibernate mappings. I would then use the Factory pattern to create the object of the specific type using your metadata.</p>\n'}, {'answer_id': 51934, 'author': 'zappan', 'author_id': 4723, 'author_profile': 'https://Stackoverflow.com/users/4723', 'pm_score': 2, 'selected': True, 'text': '<p>@Brian Chiasson</p>\n\n<p>Unfortunately, it\'s not an option to create all classes of GIS data because classes are created dynamically in the application. Every GIS data of the same type should be a class, but my user has the possibility to get new set of data and put it in the database. I can\'t know in front which classes my user will have in the application. Therefore, the in-front per-class mapping model doesn\'t work because tomorrow there will be another new database table, and a need to create new class with new mapping.</p>\n\n<p>@all\nThere might be a possibility to write my own custom query in the XML config file of my GisObject class, then in the data access class fetching that query using the </p>\n\n<pre><code>string qs = getSession().getNamedQuery(queryName);\n</code></pre>\n\n<p>and use the string replace to inject database name (by replacing some placeholder string) which i will pass as a parameter. </p>\n\n<pre><code>qs = qs.replace(":tablename:", tableName);\n</code></pre>\n\n<p>How do you feel about that solution? I know it might be a security risk in an uncontrolled environment where the table name would be fetched as the user input, but in this case, i have a meta table containing right and valid table names for the GIS data classes which i will read before calling the query for fetching data for the specific class of GIS objects.</p>\n'}, {'answer_id': 53476, 'author': 'MotoWilliams', 'author_id': 2730, 'author_profile': 'https://Stackoverflow.com/users/2730', 'pm_score': 0, 'selected': False, 'text': "<p>I guess I'd ask the question to why you are going after the GIS data directly in the database and not using what API that is typically provided as an abstraction for you.  If this is an ESRI system there are tools that allow you to create static database views into their GIS objects and then maybe from that point it might be appropriate for data extract.</p>\n"}, {'answer_id': 98574, 'author': 'Eric Lathrop', 'author_id': 18392, 'author_profile': 'https://Stackoverflow.com/users/18392', 'pm_score': 0, 'selected': False, 'text': '<p>From the NHibernate documentation, you could use one of the <a href="http://www.hibernate.org/hib_docs/nhibernate/html/inheritance.html" rel="nofollow noreferrer">inheritance mappings</a>.</p>\n\n<p>You might also have a separate class for each table, but have them all implement some common interface</p>\n'}]
['https://Stackoverflow.com/questions/51654', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4723/']