Spatial Data type support in Entity Framework 5.0

MS SQL Server 2008 introduced two spatial data types, geography and geometry. Geography represents data in a round-earth coordinate system and geometry represent data in a Euclidean (flat) coordinate system.

Entity Framework supports spatial data types DbGeography and DbGeometry since version 5.0. Let's see how we can use these data types.

For demo purposes, we have changed the data type of the Location column of Course table to geography in SQL Server 2008 as shown below:

Now, create an entity data model (.edmx) after having geography column in the database as shown in previous chapter section. After creating EDM, you can see that the type of Location property of Course entity is System.Data.Spatial.DBGeography as shown below:

public partial class Course
{
public Course()
{
this.Students = new HashSet<Student>();
} public int CourseId { get; set; }
public string CourseName { get; set; }
public Nullable<int> TeacherId { get; set; }
public System.Data.Spatial.DbGeography Location { get; set; } public virtual Teacher Teacher { get; set; }
public virtual ICollection<Student> Students { get; set; }
}

You can now use the Location property in CRUD operation using DBContext as shown in the following example.

using (var ctx = new SchoolDBEntities())
{
ctx.Courses.Add(new Course() { CourseName = "New Course",
Location = DbGeography.FromText("POINT(-122.360 47.656)") }); ctx.SaveChanges();
}

Visit MSDN for more information on geography data type and geometry data typeof MS SQL Server 2008.

Entity Framework Tutorial Basics(33):Spatial Data type support in Entity Framework 5.0的更多相关文章

  1. Entity Framework Tutorial Basics(35):Local Data

    Local Data The Local property of DBSet provides simple access to the entities that are currently bei ...

  2. Entity Framework Tutorial Basics(32):Enum Support

    Enum in Entity Framework: You can now have an Enum in Entity Framework 5.0 onwards. EF 5 should targ ...

  3. Entity Framework Tutorial Basics(1):Introduction

    以下系列文章为Entity Framework Turial Basics系列 http://www.entityframeworktutorial.net/EntityFramework5/enti ...

  4. Entity Framework Tutorial Basics(4):Setup Entity Framework Environment

    Setup Entity Framework Environment: Entity Framework 5.0 API was distributed in two places, in NuGet ...

  5. Entity Framework Tutorial Basics(41):Multiple Diagrams

    Multiple Diagrams in Entity Framework 5.0 Visual Studio 2012 provides a facility to split the design ...

  6. Entity Framework Tutorial Basics(27):Update Entity Graph

    Update Entity Graph using DbContext: Updating an entity graph in disconnected scenario is a complex ...

  7. Entity Framework Tutorial Basics(22):Disconnected Entities

    Disconnected Entities: Before we see how to perform CRUD operation on disconnected entity graph, let ...

  8. Entity Framework Tutorial Basics(20):Persistence in Entity Framework

    Persistence in Entity Framework There are two scenarios when persisting an entity using EntityFramew ...

  9. Entity Framework Tutorial Basics(5):Create Entity Data Model

    Create Entity Data Model: Here, we are going to create an Entity Data Model (EDM) for SchoolDB datab ...

随机推荐

  1. Android Volley完全解析(四),带你从源码的角度理解Volley

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/17656437 经过前三篇文章的学习,Volley的用法我们已经掌握的差不多了,但是 ...

  2. Python之用虚拟环境隔离项目,并重建依赖关系

    下面将以安装django和mysqlclient介绍如何用虚拟环境隔离项目,并重建依赖关系.操作系统:windows 10:python版本:python3.7 1. 安装python虚拟环境 (1) ...

  3. 开发mis系统用到的技术

    1. b/s架构:就broser/server,浏览器/服务器的说法.服务器端要运行tomcat,提供链接数据库服务供java代码读写数据,这个可以在eclipse中配置运行.浏览器则解释jsp或ht ...

  4. Unity 头发随动效果

    目标 实现角色的衣袖.头发.裙摆.披风.尾巴等,在角色运动时,可以产生随动的效果.类似王者荣耀角色展示界面. 准备 源码出出处:https://github.com/unity3d-jp/unityc ...

  5. 【Unity】publishing setting keystore作用

    http://blog.csdn.net/ldy597321444/article/details/53519753 android的默认调试签名,所有市场都不允许debug签名的应用发布的.所以,第 ...

  6. linux 内核的链表操作(好文不得不转)

    以下全部来自于http://www.ibm.com/developerworks/cn/linux/kernel/l-chain/index.html 无任何个人意见. 本文详细分析了 2.6.x 内 ...

  7. 第一章计算机网络和因特网-day02

    1.互联网中的时延:处理时延.排队时延.传输时延.传播时延. 处理时延:检查分组首部和决定该分组导向何处的时间. 排队时延:分组在链路上等待传输的时延. 传输时延:分组经过路由器与交换机的过程的时延. ...

  8. kibana 统计field所有值百分比

    步骤: 1.创建新的Visualize——Pie chart 2.工具栏设置 metrics: slice size Count (默认) buckets:Split Slices 注意调整size: ...

  9. CentOS 7 安装Percona,Xtrabackup

    CentOS 7 安装Percona 5.7,Xtrabackup 简介 Percona Server为 MySQL 数据库服务器进行了改进,在功能和性能上较 MySQL 有着很显著的提升.该版本提升 ...

  10. L3-001. 凑零钱(dfs或者01背包)

    L3-001. 凑零钱 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 韩梅梅喜欢满宇宙到处逛街.现在她逛到了一家火星店里,发现 ...