Persistent Ignorant Domain with Entity Framework and Spacial Data

c# domain-driven-design entity-framework entity-framework-6

Popular Answer

I don't know the "correct" technique, but I do have a complex idea. I hope it will be useful to you or provide some additional options: You own this domain entity.Place , its position in the Domain assembly, and its complete persistence in ignorance. Good. Let's add a third Place class to 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 :)
        }
    }
}

For Entity Framework, we developed a special class, and we mapped it to:

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

But when saving to the repository, we must convert from Place to EFPlace. You can develop a casting method or a specific constructor. Create partial classes for Place in the Domain and Repository assemblies as an alternative. And then add the required properties to each subsequent class in the repository. Well, it's not pretty: ( But I'm not aware of any "pure" instances of persistent ignorance in the real world. Entity Framework has ongoing constraints. The attributes of NHibernate are slightly more.

0
8/10/2015 2:29:19 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow