实体框架与SQL Compact Edition-如何获取ntext? [英] Entity Framework & SQL Compact Edition - how do I get ntext?

查看:65
本文介绍了实体框架与SQL Compact Edition-如何获取ntext?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题的答案应该很明显,但是我找不到.我有一个有一个表的edmx文件.有一个类型为 string 的字段.EF总是为此生成nvarchar(这是预期的),但是对于该字段,我需要一个 ntext 而不是 nvarchar ,因为4000也是如此对我来说很小.

The answer to my question should be quite obvious, but I cannot find it. I have a edmx file that has one table. There is a field of type string. EF always generates nvarchar for that (which is kind of expected), but I need an ntext instead of nvarchar for that field as 4000 is too small for me.

那么,告诉我-告诉EF生成 ntext 字段的正确方法是什么?

So tell me - what is the proper way to tell EF to generate ntext fields?

使用实体框架4的PS,SQL CE 3.5

PS Using Entity Framework 4, SQL CE 3.5

推荐答案

我想您首先使用模型,不是吗?您可以简单地为SQL DDL生成创建自定义的T4模板,并包括在字段以最大大小定义时将使用 NTEXT 的逻辑.

I guess you are using model first, don't you? You can simply create custom T4 template for SQL DDL generation and include logic which will use NTEXT when field is defined with max size.

默认模板已启用:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\DBGen\SSDLToSQL10.tt

只需复制此模板并找到在其中创建数据类型的逻辑.拥有模板后,将模型属性(在设计器中)的"DDL生成模板"更改为修改后的版本.

Just copy this template and find the logic where data type is created. Once you have your template change DDL Generation Template in model properties (in the designer) to your modified version.

There is much more you can do with generation template because you can add some annotations to your model (XML) and use them for custom logic in the SQL generation process.

这篇关于实体框架与SQL Compact Edition-如何获取ntext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆