开发者

NHibernate and interfaces with different implementations

开发者 https://www.devze.com 2023-03-21 05:58 出处:网络
I have recently started working with C# and NHibernate so all this is quite novice to me. In the application I\'m building I need to calculate distances between UK postcodes.

I have recently started working with C# and NHibernate so all this is quite novice to me.

In the application I'm building I need to calculate distances between UK postcodes. One of the approaches is to use grid reference and Pythagoras distance. Another approach is to use Google Maps to get distances.

I have an interface Ipostcode with method getDistance(IPostcode p) and depending on implementations classes will be talking to different tables.

For Grid References I'll have GridRefPostcode object and DB table: (string)postcode, (lo开发者_如何学编程ng)northing, (long)easting.

For Google Maps I'll GoogleMapsPostcode object and DB table: (string)postcode, (string)otherPostcode, (double)distance.

Class Person will have a field IPostcode, and then I'll be calculating distances based on getDistance() provided by both classes.

Now the question is: How to map this class-relationship in NHibernate? How I can fit interface into mapping?

                   Person
                      ^
                      |
                  IPostcode ( Interface )
                   ^     ^
                   |     |
      GridRefPostcode    GoogleMapsPostcode

Is it even possible? I have a gut feeling that my class structure needs to be changed completely, but this seems to be the most reasonable solution: If I have distance between 2 postcodes provided by Google, I use it, if it is not available, I step down to GridReferences.

Any ideas are highly appreciated!

0

精彩评论

暂无评论...
验证码 换一张
取 消