有没有办法在枚举中添加"所有值"选项而不必在每次将新值添加到枚举时更改其值?
[Flags]
public enum SomeEnum
{
SomeValue = 1,
SomeValue2 = 1 << 1,
SomeValue3 = 1 << 2,
SomeValue4 = 1 << 3,
All = ?
}
Run Code Online (Sandbox Code Playgroud)
更新:
结束从long继承并使用long.MaxValuefor All选项.
我收到错误:
在LINQ表达式中检测到循环.
在ToList()尝试执行以下操作时:
private IEnumerable<int> FilterIdsByClient(IEnumerable<int> entityIds)
{
entityIds =
MyObjectContext.CreateObjectSet<TEntity>()
.Where(x => x.ClientId == _clientId)
.Where(x => entityIds.Contains(x.Id))
.Select(x => x.Id);
return entityIds.ToList();
}
Run Code Online (Sandbox Code Playgroud)
但是这不会抛出任何异常并且工作正常:
private IEnumerable<int> FilterIdsByClient(IEnumerable<int> entityIds)
{
entityIds =
MyObjectContext.CreateObjectSet<TEntity>()
.Where(x => x.ClientId == _clientId)
.Where(x => entityIds.Contains(x.Id))
.Select(x => x.Id)
.ToList();
return entityIds;
}
Run Code Online (Sandbox Code Playgroud)
(当然这是一个简单的版本).
任何人都知道为什么会发生这种奇怪的行为?
编辑:
这是堆栈跟踪:
at System.Data.Objects.ELinq.Funcletizer.FuncletizingVisitor.Visit(Expression exp)
at System.Data.Objects.ELinq.Funcletizer.Funcletize(Expression expression, Func`1& recompileRequired)
at System.Data.Objects.ELinq.Funcletizer.FuncletizingVisitor.InlineExpression(Expression exp)
at System.Data.Objects.ELinq.Funcletizer.FuncletizingVisitor.InlineObjectQuery(ObjectQuery inlineQuery, Type expressionType)
at System.Data.Objects.ELinq.Funcletizer.FuncletizingVisitor.InlineValue(Expression expression, Boolean recompileOnChange)
at System.Data.Objects.ELinq.Funcletizer.FuncletizingVisitor.Visit(Expression exp)
at …Run Code Online (Sandbox Code Playgroud) 我有一个包含大量数据的表,我需要将它与其他一些大表连接起来.
我的桌子中只有一小部分每次都与我有关.
什么时候最好过滤我的数据?
在SQL的where子句中.
使用特定数据创建临时表,然后才加入它.
将谓词添加到第一个内连接ON子句.
其他一些想法.
1.
Select *
From RealyBigTable
Inner Join AnotherBigTable On …
Inner Join YetAnotherBigTable On …
Where RealyBigTable.Type = ?
Run Code Online (Sandbox Code Playgroud)
2.
Select *
Into #temp
From RealyBigTable
Where RealyBigTable.Type = ?
Select *
From #temp
Inner Join AnotherBigTable On …
Inner Join YetAnotherBigTable On …
Run Code Online (Sandbox Code Playgroud)
3.
Select *
From RealyBigTable
Inner Join AnotherBigTable On RealyBigTable.type = ? And …
Inner Join YetAnotherBigTable On …
Run Code Online (Sandbox Code Playgroud)
另一个问题:先发生什么?Join还是Where?
我有一个有很多旧注册版本的程序集.
我唯一的dll是最后一个.
如何取消注册程序集的所有版本?
谢谢.
编辑:我想在运行时这样做,所以我想要像regasm -u ...或其他一些脚本解决方案.
我正在使用Newtonsoft.Json.JsonConvert序列化Textbox(WinForms)到json,我希望序列化跳过具有默认值或空数组的属性.
我试图使用NullValueHandling = NullValueHandling.Ignore,JsonSerializerSettings但似乎并没有影响任何东西.
这是完整的代码示例(简化):
JsonSerializerSettings settings = new JsonSerializerSettings()
{
Formatting = Formatting.None,
DefaultValueHandling = DefaultValueHandling.Ignore,
NullValueHandling = NullValueHandling.Ignore,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
ObjectCreationHandling = ObjectCreationHandling.Replace,
PreserveReferencesHandling = PreserveReferencesHandling.None,
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
};
string json = JsonConvert.SerializeObject(textbox, settings);
Run Code Online (Sandbox Code Playgroud)
有任何想法吗 ?
考虑这个表:
create table x (id int, total int, diff int)
Run Code Online (Sandbox Code Playgroud)
这个数据:
[1, 100, 20]
[2, null, 30]
[3, null, -15]
[4, null, 4]
…
Run Code Online (Sandbox Code Playgroud)
我需要根据前一行计算"总计"列.
这意味着最终数据看起来应该是这样的:
[1, 100, 20]
[2, 120, 30]
[3, 150, -15]
[4, 135, 4]
…
Run Code Online (Sandbox Code Playgroud)
这样做最有效的方法是什么?