views:

1528

answers:

6

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.

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.

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 use the table name as a parameter 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).

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

A: 

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.

lomaxx
tables are being created dynamically by the user. when user gets a new class of data (i.e. gets a collection of railroads from some source) and wants to input it in the application, new table is being created, and i need a way to access new data without doing a separate mapping to the new table.
zappan
A: 

You can have a look at what Ayende is saying here : MultiTable Entities.

But since you have separate tables , i don't think it will work. You can also check out nhuser group

sirrocco
thanks, i will try the nhusergroup. the multitable entities isn't my case....
zappan
+1  A: 

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.

+1  A: 

@Brian Chiasson

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.

@all There 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

string qs = getSession().getNamedQuery(queryName);

and use the string replace to inject database name (by replacing some placeholder string) which i will pass as a parameter.

qs = qs.replace(":tablename:", tableName);

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.

zappan
A: 

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.

MotoWilliams
i use intergraph's api, and the reason is that the api isn't well designed and built. so i'm extracting the non-gis properties into c# classes to be used in application for drop down lists, checklists and things like that. for the map rendering, the intergraph's api is used.
zappan
A: 

From the NHibernate documentation, you could use one of the inheritance mappings.

You might also have a separate class for each table, but have them all implement some common interface

Eric Lathrop