- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的数据库表中有一个字段用于存储枚举值,例如:
create table MyTable (
...
Status tinyint not null,
...
)
在我的 C# 课上我有
public enum TStatus : byte {
Pending = 1
Active = 2,
Inactive = 3,
}
public TStatus MyStatus {
get { return (TStatus)Status; }
set { Status = (byte)value; }
}
现在我想编写一个使用 MyTable
的 MyStatus
属性的 Linq 查询,例如
var q = MyDataContext.GetTable<MyTable>().Where(t => t.MyStatus == TStatus.Active);
当然,Linq 不知道如何将 MyStatus
解释为 SQL。我需要对 MyStatus
做些什么才能使其在 LinqToSQL 中工作?
最佳答案
查看此链接:
http://dotnet.org.za/hiltong/archive/2008/08/06/using-enums-with-linq-to-sql.aspx
随着链接的消失——至少对我来说,这个链接确实消失了——这里是重要的部分:
[When adding the column to the entity] by default, the Type will come up as an "int (System.Int32)", but you can change it to the fully-qualified type of the enum (in my case, ConsoleApplication1.CustomerType). BUT, in order to locate it fully, you have to add the global identifier, as follows: global::ConsoleApplication1.CustomerType , so type that as is (but the equivalent for your namespace) into the textbox
关于c# - 如何在 LinqToSQL 查询中使用我的枚举?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1007811/
我是一名优秀的程序员,十分优秀!