博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Entity Framework Tutorial Basics(33):Spatial Data type support in Entity Framework 5.0
阅读量:7279 次
发布时间:2019-06-30

本文共 1653 字,大约阅读时间需要 5 分钟。

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  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
(); } public int CourseId { get; set; } public string CourseName { get; set; } public Nullable
TeacherId { get; set; } public System.Data.Spatial.DbGeography Location { get; set; } public virtual Teacher Teacher { get; set; } public virtual ICollection
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  and of MS SQL Server 2008.

转载于:https://www.cnblogs.com/purplefox2008/p/5649221.html

你可能感兴趣的文章
蓝色心情win7主题一键安装包 v 2.0
查看>>
MySQL5.7修改密码
查看>>
10个趣味Linux动画命令
查看>>
Linux协议栈(4)——sk_buff及代码
查看>>
DDOS防御
查看>>
python 学习笔记
查看>>
python的property语法的使用
查看>>
Gartner新报告: IaaS营收增长迅速 云计算市场2020年达4千亿
查看>>
照片美妆---卷积“换脸”
查看>>
linux内存管理
查看>>
Nginx配置文件nginx.conf详解
查看>>
常见的几种系统平台及文件系统
查看>>
oracle database guard
查看>>
TortoiseGit之配置密钥
查看>>
linux下apache+php安装常见问题
查看>>
ubuntu常用命令
查看>>
对Delphi 7/Delphi 2007的Windows服务类库的一个小改进
查看>>
了解你所不知道的SMON功能(二):合并空闲区间
查看>>
mysqldump备份数据库,并删除7天前的备份文件脚本
查看>>
webbench 网站压力测试工具
查看>>