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 ...
随机推荐
- New Concept English three (49)
31w/m 51error It is a good thing my aunt Harriet died years ago. If she were alive today she would n ...
- @media screen页面自适应尺寸!!
@media screen and (max-width:360px){body,input,select{font-size:38%}} @media screen and (min-width:3 ...
- CodeForces - 156D:Clues(矩阵树定理&并查集)
题意:给定N点,M边,求添加最少的边使之变为连通图的方案数. 思路:注意题目给出的M边可能带环,即最后生成的不一定是一棵树.但是影响不大.根据矩阵树定理,我们知道生成树的数量=N^(N-2),即点数^ ...
- 转载:jquery插件实现图片延迟加载(lazyload.js)
转载: http://www.cnblogs.com/tinyphp/archive/2013/04/09/3009385.html
- Python的交互模式和命令行模式
Pyhton的交互模式 在终端输入Python3命令就会进入家Python的交互模式,在交互模式下,输入一行代码,回车,就会执行这行代码. Python的命令行模式 在终端输入Python3 1.py ...
- 快速沃尔什变换(FWT)学习笔记
概述 FWT的大体思路就是把要求的 C(x)=A(x)×B(x) 即 \( c[i]=\sum\limits_{j?k=i} (a[j]*b[k]) \) 变换成这样的:\( c^{'}[i]=a^ ...
- 异常:java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlType
这个是jdK版本的问题的. 本地编译的jar包是1.8的,但是跑jar包的环境jdk版本是1.9的. 升级1.9之后由于jdk当方面的取消了几个jar,所以导致编译起不来. 明天研究一下如何添加jar ...
- CentOS7下Supervisor安装与配置
Supervisor(http://supervisord.org/)是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统 ...
- java文本文件读写
java的IO系统中读写文件使用的是Reader和Writer两个抽象类,Reader中的read()和close()方法是抽象方法,Writer中的write().flush()和close()方法 ...
- thinkphp <volist>标签中 <if> 判断的写法
thinkphp <volist>标签中 <if> 判断的写法 <volist name="data" id="vo"> & ...