Permanent non-identical domain with entity platform and spatial data

I am developing an application that implements DDD and repository template, as shown in the figure below:

My software architecture

I expect my domain level to be unstable, so I would not want to install entity libraries there. The only problem I am facing is that my application uses spatial data, but I should not use DbGeography as a property type of my objects, as soon as it belongs to the System.Data.Entity.Spatial namespace from the EntityFramework assembly.

Is there a way to create a class to store latitude, longitude, and height values ​​in a domain layer, for example:

public class Location { public double Latitude { get; set; } public double Longitude { get; set; } public double Elevation { get; set; } } 

and then convert this class to DbGeography at my repository level?

In other words, domain objects will only have the Location class as a property:

 public class Place : IEntityBase, ILocalizable { public int Id { get; set; } public string Name { get; set; } public Location Location { get; set; } public User Owner { get; set; } } 

and I would convert it to DbGegraphy to save spatial data and do some calculations only in the repository layer. My plans are to try something similar for conversion:

 public class LocationMap : ComplexTypeConfiguration<Location> { public LocationMap() { Property(l => DbGeography.FromText(string.Format("POINT({0} {1})", l.Longitude, l.Latitude))).HasColumnName("Location"); Ignore(l => l.Elevation); Ignore(l => l.Latitude); Ignore(l => l.Longitude); } } 

But it does not work and never will be. How can I solve this problem? What are the best practices in this situation?

thanks

+6
source share
1 answer

Well, I don’t know the “right” way, but I have a difficult idea. I hope this helps you or gives you several options: Ypu has the domain entity Place , it is completely persistent, ignorant and fits into the domain assembly. Good. Allows you to create another class of the class in the repository assembly:

 internal sealed class EFPlace : Place { DbGeography EFLocation { get { return DbGeography.FromText(string.Format("POINT({0} {1})", Location.Longitude, Location.Latitude); } set { //vice versa convertion, I don't know, how to do it :) } } } 

We created a special class for the Entity Framework and on it:

 public class PlaceMap : ComplexTypeConfiguration<EFPlace> { public PlaceMap () { Property(p => p.EFLocation).HasColumnName("Location"); Ignore(p => p.Location); } } 

But we need to convert from Place to EFPlace when saving to the repository. You can create a special constructor or casting method. Another option is to create a partial Place class in the Domain and Repository assemblies. And add the required property to the repository of one class and so on. Well, that looks ugly: (but I don’t know the “clean”, real examples of persistent ignorant domain. We always have the limitations of the Entity Framework. NHibernate has a bit more features.

0
source

All Articles