我有枚举:
public enum Operation {
/// <remarks/>
[System.Xml.Serialization.XmlEnumAttribute("01")]
Item01,
/// <remarks/>
[System.Xml.Serialization.XmlEnumAttribute("02")]
Item02,
/// <remarks/>
[System.Xml.Serialization.XmlEnumAttribute("03")]
Item03,
/// <remarks/>
[System.Xml.Serialization.XmlEnumAttribute("04")]
Item04,
}
Run Code Online (Sandbox Code Playgroud)
我如何获得XmlEnumAttribute值?
我正在努力:
var res = Operation.Item1;
var result = (res.GetType().GetField("Item01").GetCustomAttributes(typeof(XmlEnumAttribute), true)[0] as XmlEnumAttribute).Name;
Run Code Online (Sandbox Code Playgroud)
可能存在更好的方法吗?
我不能在两种转换方法之间进行选择.从枚举转换为int的最佳实践是什么?
1:
public static int EnumToInt(Enum enumValue)
{
return Convert.ToInt32(enumValue);
}
Run Code Online (Sandbox Code Playgroud)
2:
public static int EnumToInt(Enum enumValue)
{
return (int)(ValueType)enumValue;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Expression并传递给查询.但我有错误 - LINQ to Entities不支持LINQ表达式节点类型'Lambda'.我也使用linqkit.dll和AsExpandable(),但是有相同的错误.
public List<Correct> GetCorrects(Expression<Func<Correct, bool?>> predicate)
{
using (SystemsEntities context = new SystemsEntities())
{
var result = context.Corrects.Where(x => predicate == null);
return result.ToList();
}
}
Run Code Online (Sandbox Code Playgroud)
我收到上述错误.什么失败了?
I have a method for updating some tables. For update I need get first of TestProcess, but I don't like that. How can I update TestProcess without select(firstOrDefault) operation, used only for the update operation?
Example of method:
public void UpdateTestProcess(int id, string updateID)
{
using (TestEntities context = new TestEntities())
{
TestProcess pr = context.TestProcess.FirstOrDefault(x => x.MyID == id);
pr.UpdateID = updateID;
context.TestProcess.Attach(pr);
context.ObjectStateManager.ChangeObjectState(pr, EntityState.Modified);
context.SaveChanges();
}
}
Run Code Online (Sandbox Code Playgroud) 如何手写映射最好的方式List<T1>来List<T2>?
我的示例类:
public class T1
{
public int ID {get; set}
public string Name {get; set}
}
public class T2
{
public int ID {get; set}
public string Name {get; set}
}
Run Code Online (Sandbox Code Playgroud) 我有MyModel类和MyModel的一些对象.
我需要没有反射的对象的for循环或foreach属性.如何实施?
类示例:
public class MyModel
{
public string Level1_TypeName { get; set; }
public string Level1_AttrType { get; set; }
public string Level1_AttrValue { get; set; }
public string Level2_TypeName { get; set; }
public string Level2_AttrType { get; set; }
public string Level2_AttrValue { get; set; }
public string Level3_TypeName { get; set; }
public string Level3_AttrType { get; set; }
public string Level3_AttrValue { get; set; }
public string Level4_TypeName { get; set; }
public string Level4_AttrType …Run Code Online (Sandbox Code Playgroud)