开发者

Use enum in LinQ

开发者 https://www.devze.com 2023-03-28 12:43 出处:网络
need help I have this enum which sets the PayClassNo to Direct and Indirect. I want to use this enum in my LinQ query.

need help

I have this enum which sets the PayClassNo to Direct and Indirect. I want to use this enum in my LinQ query.

Here's my scratch LinQ query:

var jDef = from jd in context.GetTable<RJVDefinition>()
                       select new PayrollJVDefin开发者_StackOverflowition
                       {
                           JVdefNo = jd.JVDefNo,
                           AccntCode = jd.AccntCode,
                           AccntDesc = jd.AccntDesc,
                           PayClass = enum.GetValue(jd.PayClassNo),
                           IsFixed = jd.IsFixed,
                           IsEmployee = jd.IsFixed,
                           IsAR = jd.IsAR,
                           CreatedByNo = jd.CreatedByNo,
                           CreatedDate = jd.CreatedDate,
                           ModifiedByNo = jd.ModifiedByNo,
                           ModifiedDate = jd.ModifiedDate
                       };

Need help because I'm not sure if this will work.


You could certainly do the translation in code, similar to your example (using Enum.Parse), but you don't need to. You can use the designer to set the object property type to an enumerated value. See this article for details.


You just need to parse the Enum just use something like

Enum.Parse(jb.PayClassNo, YourEnumType)
0

精彩评论

暂无评论...
验证码 换一张
取 消