Entity Framework: SqlGeography vs DbGeography

前端 未结 1 1232
死守一世寂寞
死守一世寂寞 2020-12-16 15:40

What is the difference, or intended purpose of these two object that represent the same Geography datatype in a Microsoft SQL Database?

System.Data.Entity.Sp         


        
相关标签:
1条回答
  • 2020-12-16 16:04

    You're right, in essence it is that simple. DbGeography is just a dumbed down version of SqlGeography, designed to work within the Entity Framework. The most popular methods of SqlGeography have been implemented within it but as you rightly point out, not all.

    Whilst the two types cannot be directly cast between each other, the process of converting them is relatively simple in times where the additional functionality of SqlGeography is required.

    For example:

    SqlGeography geog1 = SqlGeography.STPolyFromText('<coords>', srid);
    SqlGeography geog2;
    DbGeography dbGeog;
    
    // SqlGeography to DbGeography
    dbGeog = DbGeography.FromText(geog1.ToString(), srid);
    // DbGeography to SqlGeography
    geog2 = SqlGeography.Parse(dbGeog.AsText());
    
    0 讨论(0)
提交回复
热议问题