Entity Framework Tutorial Basics(33):Spatial Data type support in Entity Framework 5.0
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的更多相关文章
- Entity Framework Tutorial Basics(35):Local Data
Local Data The Local property of DBSet provides simple access to the entities that are currently bei ...
- 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 ...
- Entity Framework Tutorial Basics(1):Introduction
以下系列文章为Entity Framework Turial Basics系列 http://www.entityframeworktutorial.net/EntityFramework5/enti ...
- 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 ...
- Entity Framework Tutorial Basics(41):Multiple Diagrams
Multiple Diagrams in Entity Framework 5.0 Visual Studio 2012 provides a facility to split the design ...
- Entity Framework Tutorial Basics(27):Update Entity Graph
Update Entity Graph using DbContext: Updating an entity graph in disconnected scenario is a complex ...
- Entity Framework Tutorial Basics(22):Disconnected Entities
Disconnected Entities: Before we see how to perform CRUD operation on disconnected entity graph, let ...
- Entity Framework Tutorial Basics(20):Persistence in Entity Framework
Persistence in Entity Framework There are two scenarios when persisting an entity using EntityFramew ...
- 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 ...
随机推荐
- zoj1967 poj2570 Fiber Network (floyd算法)
虽然不是最短路,但是询问时任意两点之间的信息都要知道才能回答,由此联想到floyd算法,只要都floyd算法的原理理解清楚了就会发现:这道题的思想和求任意两点之间的最短路的一样的,只不过是更新的信息不 ...
- 2016 ACM-ICPC 区域赛(大连站)题解
题目链接 A - Wrestling Match (二分图染色) 题意略坑(没有说好的玩家一定能打过差的玩家啊啊~~) 典型的二分图染色问题,每个玩家看成一个点,把相互较量过的玩家之间连边,好的玩家染 ...
- CodeForces - 156D:Clues(矩阵树定理&并查集)
题意:给定N点,M边,求添加最少的边使之变为连通图的方案数. 思路:注意题目给出的M边可能带环,即最后生成的不一定是一棵树.但是影响不大.根据矩阵树定理,我们知道生成树的数量=N^(N-2),即点数^ ...
- jacksi(比较实用的工具批处理)
批处理类别: 国产软件 批处理语言: 简体中文 授权方式: 免费软件 运行环境: Windows平台 警告:运行BAT源码是一种危险的动作,如果你不熟悉,请不要尝试! 这里分享的是用bat写的比较实用 ...
- Python函数-cmp()
cmp(x, y) 作用: 比较两个对象x和y,如果x < y ,返回负数:x == y, 返回0:x > y,返回正数. 注:在python2所有版本中都可用,但在pyt ...
- gulp之文件合并以及整合html中的script和link
gulp的文件合并,也就是将多个js或css文件合并为一个的插件是:gulp-concat gulp将html中的多个<script>或<link>合并为一个的插件是:gulp ...
- 第9章 DOM对象,控制HTML元素
学习地址:http://www.imooc.com/learn/10
- nc之一:NetCat简介与使用方法
精品学习网考试频道小编应广大考生的需要,特为参加考试的考生策划了“NetCat简介与使用方法”专题等有关资料,供考生参考! 在入侵中它是最经典的工具之一 ,NetCat被所有的网络安全爱好者和研究者称 ...
- 转:InnoDB Log Block Structure(InnoDB日志Block结构详解)
文章转载自等博 InnoDB Log Block Structure(InnoDB日志Block结构详解)
- nginx upstream的几种配置方式
nginx 的upstream目前支持4种方式的分配 1.轮询(默认) 每个请求按时间顺序逐一分配到不同的后端服务器 ,如果后端服务器down掉,能自动剔除. 2.weight指定轮询几率,weigh ...