linq对orm的datamodal扩展枚举属性的问题
我对linq 生成的dbml对象添加了个扩展,在扩展中使用了枚举
public enum Rising
{
hold = 0,
rise = 1,
down = 2
}
public partial class ADS_INFO_GROUP
{
[Column(Name = "CRM_Flag", DbType = "NChar(1) NOT NULL")]
public Rising BooleanCRM
{
get
{
switch (this.CRM_Flag)
{
case '0':
return Rising.hold;
case '1':
return Rising.rise;
case '2':
return Rising.down;
default:
return Rising.hold;
}
}
set
{
switch (value)
{
case Rising.hold:
this.CRM_Flag = '0';
break;
case Rising.rise:
this.CRM_Flag = '1';
break;
case Rising.down:
this.CRM_Flag = '2';
break;
}
}
}
}
可是问题是我在linq查询中使用这个扩展的枚举属性的时候
var OwnerGroup = from ADS_INFO_GROUP_OWNER in dc.ADS_INFO_GROUP_OWNERs
join ADS_INFO_GROUP in dc.ADS_INFO_GROUPs on ADS_INFO_GROUP_OWNER.Group_Id equals ADS_INFO_GROUP.Group_Id
where ADS_INFO_GROUP_OWNER.User_Id == user.User_Id && ADS_INFO_GROUP.BooleanCRM == Rising.down
select ADS_INFO_GROUP;
linq生成的sql 总是将这个枚举值认成一个很怪的字符,而不是我在set中定义的值,请问这种情况应该怎么处理呀?
------解决方案--------------------
CRM_Flag应该是tinyint吧
你是char,然后char=0或1或2都是乱码。。。
------解决方案--------------------ding
------解决方案--------------------使用枚举的话为什么数据库要用nchar类型?
尝试把char转为int,用int.Parse()来转,然后直接用(Rising)int值
看看这样行不行
------解决方案--------------------顶你