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. C语言编译全过程

    编译的概念:编译程序读取源程序(字符流),对之进行词法和语法的分析,将高级语言指令转换为功能等效的汇编代码,再由汇编程序转换为机器语言,并且按照操作系统对可执行文件格式的要求链接生成可执行程序.    ...

  2. UVA 11637 Garbage Remembering Exam

    #include <iostream> #include <stdio.h> #include <cstring> #include <math.h> ...

  3. Java演示手机发送短信验证码功能实现

    我们这里采用阿里大于的短信API 第一步:登陆阿里大于,下载阿里大于的SDK a.在阿里大于上创建自己的应用 b.点击配置管理中的验证码,先添加签名,再配置短信模板 第二步:解压相关SDK,第一个为j ...

  4. javascript之面试题精讲

    from:http://blog.csdn.net/q121516340/article/details/51332454 1,检测数组的几种方式: Array.isArray(); es5 toSt ...

  5. (C#)Windows Shell 外壳编程系列4 - 上下文菜单(iContextMenu)(二)嵌入菜单和执行命令

    (本系列文章由柠檬的(lc_mtt)原创,转载请注明出处,谢谢-) 接上一节:(C#)Windows Shell 外壳编程系列3 - 上下文菜单(iContextMenu)(一)右键菜单 上一节说到如 ...

  6. Python修复图像文件后缀名

    网上爬了很多图片,有很多错误. 有的不是图片文件,需要删除 有的后缀名错误,需要更正 用的的python脚本 #!/usr/bin/env python #-*- coding: utf-8 -*-# ...

  7. 手把手教你创建Azure ARM Template

    Azure的ARM模式在中国已经落地了.在ARM模式中,通过ARM的Template批量的创建各种资源是与ASM模式的最大的区别之一.目前Azure ARM的Template数量已经越来越多,更多的客 ...

  8. JSF中使用f:ajax标签无刷新页面改变数据

    ajax本是用在前端的一种异步请求数据的操作,广泛用于js中,一般的js框架如jq都有被封装好的方法,用于发起异步请求操作.异步操作可以增强用户体验和操作,越来越多的程序都在使用ajax.JSF的fa ...

  9. Redis value的5种类型及常见操作

    Redis本身存储就是一个hash表,实际实࣫比hash表更复一些,后续讲存储结构时会细讲Key只有String类型Value包括String ,Set,List,Hash,Zset五中类型 STRI ...

  10. 11-18网页基础--第二部分CSS样式属性(1)

    第一课:样式属性 style 样式:style样式不仅可以直接在<body>中设置成整个网页的样式.格式:为了将样式.格式多样化,也可以将style单独抽出来,作为一个独立的个体,放在&l ...