EF4 CodeFirst CTP5:关于如何实现类型转换的问题 [英] EF4 CodeFirst CTP5: Question about how to achieve type conversion

查看:102
本文介绍了EF4 CodeFirst CTP5:关于如何实现类型转换的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我对类型转换有疑问。


假设我有一个类型为"int"的列在数据库方面,我希望将相应的属性设为  a"string"在实体方面。我怎么能用CodeFirst做到这一点?


我在我的EntityTypeConfiguration类中尝试了以下语句:


 
Property(st => st.Id).HasColumnType(" INT" ); // st.Id是一个"字符串"

解决方案

尝试使用StoreType,如下所示:


 


Property(st => st.Id) .StoreType =" int";



Property(st => st.Id).HasStoreType(" int");


Hi guys,

I have a question regarding type conversion.

Assuming I have a column of type "int" on the DB side and I want to have the corresponding property as  a "string" on the entity side. How can I do that using CodeFirst?

I have tried the following statement into my EntityTypeConfiguration class:

Property(st => st.Id).HasColumnType("int");  // st.Id is a "string"

解决方案

Try using the StoreType, something like this:

 

Property(st => st.Id).StoreType = "int";

or

Property(st => st.Id).HasStoreType("int");


这篇关于EF4 CodeFirst CTP5:关于如何实现类型转换的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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