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 ...
随机推荐
- Image Pyramid
今天我们介绍图像处理邻域中比较常用的一种方法,image pyramid, 也叫图像金字塔.就是将图像进行一层一层的下采样,图像金字塔是为了构建图像的多尺度,让模型能够更好的适应图像的尺度变化,图像金 ...
- wordpress 自定义删除后台管理菜单
<?php /* //wordpress共有5种角色:administrator(管理员) editor(编辑) author(作者) contributor(投稿者) subscriber(订 ...
- Phone numbers
Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, ...
- Unity项目UI图片压缩格式(UGUI)
http://blog.csdn.net/bobodan123/article/details/70316538 UI制作时候使用的是Ps 8位 RGB通道的色彩. 但导出的是16位RGBA色彩的图片 ...
- 证书脚本--生成csr,key
#!/bin/sh # this script can make certificate of each line in file you point which one! if [ $# -ne 1 ...
- IHE 官方网址有用资源介绍
实现标准: http://www.ihe.net/Technical_Frameworks/ 各个实现框架文档, 比如XDS,XCA,PIX,PDQ等 测试工具:http://www.ihe.net/ ...
- C# 多线程参数传递
之前使用多线程的时候,基本没有遇到过参数传递的情况,最近,接连遇到需要进行参数传递的多线程的使用.每次都要重新上网查一下,太麻烦了.为了方便以后的使用,就把经常参阅的网上资料记录下来. 原文地址如下: ...
- debug时打到了URLClassLoader.class里面,
一.解决方法,查看breakpoints,看有没有在这个类里面打断点,有时会系统自动打断电在这个类里面, 二.在设置里面,找到debug,去掉debug的前面几个断电设置.
- iOS开发之---KVC全解
————————————————————————————————————————————————————————————— 一 KVC的基本概念 KVC是Key Value Coding的缩写,意思是 ...
- 利用DNS进行传输数据
曾经有这样一道题目,困了我数个小时,最后我尝试利用此方法时我知道真相的时候,眼泪已掉下来. 遇到的是一个流量分析题,分析DNS数据,拿到flag 流量如图所示: 进入linux,提取: [root@s ...