我刚开始使用NHibernate(使用SQLite)在我当前的项目中,我主要使用Query<>,因为我很熟悉在Linq中编写数据库查询.
当我遇到一些更复杂的查询时,我做了一些研究,QueryOver<>并认为它应该受到青睐,Query<>因为"QueryOver语法是NH特定的".而且,似乎没有任何东西Query<>可以做到QueryOver<>无法实现.
所以我开始相应地更换所有用法Query<>.不久之后,我有了第一个"问题",使用起来Query<>似乎更方便.示例(从CustomNumber表中的列中选择最高值BillingDataEntity):
int result = Session.Query<BillingDataEntity>().Select(x => x.CustomNumber).OrderByDescending(a => a).FirstOrDefault();
int result = Session.QueryOver<BillingDataEntity>().Select(x => x.CustomNumber).OrderBy(a => a.CustomNumber).Desc.Take(1).SingleOrDefault<int>();
Run Code Online (Sandbox Code Playgroud)
我不喜欢的是需要将结果显式地转换为int,并且Query <>版本更容易阅读.我的查询完全错了,换句话说:有更好的方法吗?
我看了一下生成的SQL输出:
NHibernate: select billingdat0_.CustomNumber as col_0_0_ from "BillingDataEntity" billingdat0_ order by billingdat0_.CustomNumber desc limit 1
NHibernate: SELECT this_.CustomNumber as y0_ FROM "BillingDataEntity" this_ ORDER BY this_.CustomNumber desc limit @p0;@p0 = 1 [Type: Int32 (0)]
Run Code Online (Sandbox Code Playgroud)
我究竟在看什么?这是NHibernate进一步转换为实际数据库查询的"内部"(依赖于方法)查询吗?
考虑以下代码:
MyTask = LongRunningMethod(progressReporter, CancelSource.Token)
.ContinueWith(e =>
{ Log.Info("OnlyOnCanceled"); },
default,
TaskContinuationOptions.OnlyOnCanceled,
TaskScheduler.FromCurrentSynchronizationContext())
.ContinueWith(e =>
{ Log.Info("OnlyOnFaulted"); },
default,
TaskContinuationOptions.OnlyOnFaulted,
TaskScheduler.FromCurrentSynchronizationContext())
.ContinueWith(e =>
{ Log.Info("OnlyOnRanToCompletion"); },
default,
TaskContinuationOptions.OnlyOnRanToCompletion,
TaskScheduler.FromCurrentSynchronizationContext())
.ContinueWith(e =>
{ Log.Info("None"); },
default,
TaskContinuationOptions.None,
TaskScheduler.FromCurrentSynchronizationContext());
Run Code Online (Sandbox Code Playgroud)
当我使用提供的 CancelSource 取消任务时,输出为:
OnlyOnCanceled
None
正如预期的那样。
当 LongRunningMethod 抛出异常时,输出为:
OnlyOnFaulted
None
正如预期的那样。
当LongRunningMethod完成输出是:
None
所以ContinueWithwithTaskContinuationOptions.OnlyOnRanToCompletion没有像我期望的那样执行。
我检查MyTask.Status了最后一个ContinueWith分支,它仍然是Running. 因此,考虑到这一点,我希望跳过 OnlyOnRanToCompletion。问题是,为什么是Statusstill Running?查看调试输出,我可以看到它LongRunningMethod一直运行到最后。
由于大量的搜索结果,我只发现了非常不相关的问题printf().
为什么不uint8_t指定自己的格式字符串,但任何其他类型呢?
据我所知printf(),它必须知道提供的参数的长度,以便能够解析变量参数列表.
由于uint8_t并uint16_t使用相同的格式说明符%u,"如何printf()"知道要处理多少字节?或者uint16_t在供应时是否存在隐含的演员uint8_t?
也许我错过了一些明显的东西.
我学习使用ObjectListView在 C# 中来显示我的 MySQL 数据,我尝试在列内绘制/放置一个删除按钮,以便当我单击它时,它将删除该行。
我知道如何在列内绘制图像或进度条,但问题是我不知道如何在其中放置按钮。我在谷歌搜索时,发现有人说必须使用自定义渲染器来绘制按钮,但我不知道如何。
如何将按钮放在列内?
这个问题关系到这一个,但一直比较一般,可以独立处理.
编辑:Quartz版本是v2.0.1
根据我的理解,以下单元测试应通过:
[Test]
public void Test() {
// run every first day of month at 14:00 hours
CronExpression expression = new CronExpression("0 0 14 1 * ?");
// TimeZoneInfo.Local = {(UTC+01:00) Amsterdam, Berlin, Bern, Rom, Stockholm, Wien}
if (!TimeZoneInfo.Local.SupportsDaylightSavingTime) {
return;
}
// get "summertime" period for current timezone
var daylightChange = TimeZone.CurrentTimeZone.GetDaylightChanges(2013);
// -> daylightChange.Start {31.03.2013 02:00:00} System.DateTime
// -> daylightChange.End {27.10.2013 03:00:00} System.DateTime
// get one startpoint before and one after begin of summertime
DateTimeOffset …Run Code Online (Sandbox Code Playgroud) MSDN声明:
我很难理解这些级别的详细含义.这就是我可以做到的(开发Windows窗体应用程序):
存储特定于Windows窗体应用程序的数据但是独立的程序集/文件版本以在更新之间保留数据的正确组合是什么?
所有标志的一般解释都很好.
我正在使用功能有限的嵌入式平台,因此无法使用矢量/ STL.
这可能是一个微不足道的问题,但我没有太多的C++经验(只有C和C#,这可能让我对显而易见的c ++方法视而不见).
请考虑以下示例:
class Parent {
};
class Child : public Parent {
};
void Test(Parent* parents, uint8_t parentCount) {
// Accessing parent[x] is problematic when 'parents' contains a derived type
}
int main() {
// This is OK
Parent parents[3];
Test(parents, 3);
// This causes problems
Child children[3];
Test(children, 3);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
显然,如果提供了指向派生类数组的指针,则在Test()中迭代父类是有问题的,因为在迭代期间假定Parent的内存占用.
我看到的唯一解决方案是传递一个类型为Parent(Parent**parents)的指针数组,但这看起来很麻烦.是否有一些我不知道的C++机制,比如将数组作为引用或其他东西传递?
我有以下课程:
public class people
{
public string name { get; set; }
public string hobby { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我想显示一个这样的列表:
no | name | hobby
-----------------------
01 | kim | tv
02 | kate | pc
03 | kim | tv
04 | kate | pc
Run Code Online (Sandbox Code Playgroud)
我知道要实现这一目标的唯一方法是将人们的阶级转变为
public class people
{
public string no{ get; set; }
public string name { get; set; }
public string hobby { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
并循环List<people>设置每个no属性。
有没有更好的方法来添加索引号列?
我在C#和.Net 4.0中使用ObjectListView。我编写了重新加载列表视图的代码,然后重新选择了最后选择的索引。
重新选择代码非常简单:
olvListView.SelectedIndex = i;
Run Code Online (Sandbox Code Playgroud)
这似乎起作用,因为已选中该项目。但是,如果我然后单击向上或向下箭头,则选择将跳至第二行(无论我选择了哪一行),这表明无论i的值是多少,选择实际上都是在第一行设置的。
我在这里做错了什么?
我一直在这个页面上查找一些C++的东西.
有关复制赋值运算符的以下示例:
Example5& operator= (const Example5& x) {
delete ptr; // delete currently pointed string
ptr = new string (x.content()); // allocate space for new string, and copy
return *this;
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,这一点对我来说很清楚,但文章指出:
或者甚至更好,因为它的字符串成员不是常量,它可以重用相同的字符串对象:
Example5& operator= (const Example5& x) {
*ptr = x.content();
return *this;
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么会这样.这不是我们想要实现的第一个例子吗?:复制分配内容.为什么"重用同一个字符串对象"?
c# ×6
.net ×2
c++ ×2
c++11 ×2
winforms ×2
asynchronous ×1
avr-gcc ×1
c ×1
dst ×1
embedded ×1
nhibernate ×1
printf ×1
quartz.net ×1
task ×1
timezone ×1
unit-testing ×1