问题描述
我使用LINQ2SQL和要绑定的对象领域(这是枚举)到一个位或在数据库中的int类型。例如,我想在我的模型中的性别字段。我已经编辑了DBML,改变类型为指向我的枚举。我要为使用同样的想法,其他地区的性别和下拉列表创建单选按钮(我想我已经想通了)。我的枚举看起来像这样
I am using Linq2Sql and want to bind an objects field (which is enum) to either a bit or a int type in the database. For example I want have a gender field in my model. I have already edited the DBML and changed the Type to point to my enum. I want to create Radio buttons (which I think I have figured out) for gender and dropdown lists for other areas using the same idea. My enum looks like this
public enum Gender
{
Male,
Female
}
Mapping between DbType 'int' and Type 'Project.Models.Gender' in Column 'Gender' of Type 'Candidate' is not supported.
这是如何做到这一点映射任何想法。我缺少的东西枚举
Any ideas on how to do this mapping. Am I missing something on the enums.
推荐答案
如果你有一个 INT
枚举是这样的:
If you have an int
enum like this:
public enum Gender
{
Male = 0,
Female
}
和 INT
在你的数据库列,下测绘应该没有问题。
and int
column in your database, the next mapping should work without problem.
<Column Name="Gender" Type="global::Project.Models.Gender" DbType="Int NOT NULL"
CanBeNull="false" />
这可能是全球::
关键词是关键在这里。我有一些问题,映射整数数据类型来枚举离不开它了。
It is possible that global::
keyword is a key here. I had some problems with mapping integer data types to enums without it.
这篇关于我如何绑定枚举以位或为int的的DbType?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!