如何使用实体框架4.1“仅代码”映射char属性流畅的API [英] How do I map a char property using the Entity Framework 4.1 "code only" fluent API?
问题描述
public class Product
{
public char代码
{
get;
设置;
}
}
实体框架似乎无法映射chars(从我的模型对象创建数据库模式时,数据库中缺少此字段)。有没有可以使用流畅的API映射字符(例如字符串)?我不想更改模型对象,因为它们是旧版共享库的一部分。
Char
是实体框架=实体框架无效的原始类型不映射它。如果您检查 CSDL参考,您将看到有效类型列表( char
不在其中)
数据库 char(1)
被翻译为 string
( SQL到CSDL的翻译)。 Char
被描述为具有固定长度1的非Unicode代码字符串。
唯一的丑陋选项是使用字符串的第二个映射属性, code> char 非映射属性将只使用该属性中的 string [0]
。这只是EF中一些简单类型映射或转换器丢失的另一个例子。
I have an object that has a char property:
public class Product
{
public char Code
{
get;
set;
}
}
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
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).
Database char(1)
is translated as string
(SQL to CSDL translation). Char
is described as non-unicode string with fixed length 1.
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屋!