如何使用实体框架4.1“仅代码”映射char属性流利的API? [英] How do I map a char property using the Entity Framework 4.1 "code only" fluent API?
问题描述
我有一个对象有一个char属性:
I have an object that has a char property:
public class Product
{
public char Code
{
get;
set;
}
}
Entity Framework似乎不能映射chars(当我从模型对象创建数据库模式时,此字段从数据库中丢失)。有没有反正我可以映射char(例如到字符串)使用fluent API?我不想更改模型对象,因为它们是旧共享库的一部分。
Entity Framework doesn't seem to be able to map chars (this field is missing from the database when I create the database schema from my model objects). Is there anyway I can map the char (e.g. to a string) using the fluent API? I don't want to change the model objects as they are part of a legacy shared library.
推荐答案
Char
不是实体框架的有效基本类型=实体框架不映射它。如果您检查 CSDL参考,您将看到有效类型的列表( char 不包括在其中)。
Char
is not valid primitive type for entity framework = entity framework doesn't map it. If you check CSDL reference you will see list of valid types (char
is not among them).
数据库 char(1)
code> string ( SQL到CSDL的翻译)。 Char
描述为非固定长度为1的非Unicode字符串。
Database char(1)
is translated as string
(SQL to CSDL translation). Char
is described as non-unicode string with fixed length 1.
唯一的丑选项是第二个映射属性使用字符串, code> char 非映射属性将使用 string [0]
。这只是另一个例子,说明一些简单的类型映射或转换器在EF中丢失。
The only ugly option is second mapped property using string and your char
non-mapped property will just use string[0]
from that property. That is just another example how some simple type mapping or converters are damn missing in EF.
这篇关于如何使用实体框架4.1“仅代码”映射char属性流利的API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!