在NHibernate 3.0中,FlushMode.Auto仅在环境事务下运行时无效(即,无需启动NHibernate事务).应该是?
using (TransactionScope scope = new TransactionScope())
{
ISession session = sessionFactory.OpenSession();
MappedEntity entity = new MappedEntity() { Name = "Entity", Value = 20 };
session.Save(entity);
entity.Value = 30;
session.SaveOrUpdate(entity);
// This returns one entity, when it should return none
var list = session.
CreateQuery("from MappedEntity where Value = 20").
List<MappedEntity>();
}
Run Code Online (Sandbox Code Playgroud)
(从这个相关问题无耻地偷走的例子)
在NHibernate的来源,我可以看到这就是它检查是否有正在进行中(在一个事务SessionImpl.AutoFlushIfRequired),但相关方法(SessionImpl.TransactionInProgress)不考虑环境事务-不像它的近亲ConnectionManager.IsInActiveTransaction,这确实考虑环境事务.
nhibernate flush transactionscope distributed-transactions nhibernate-3
我想有些人可能能够回答这个问题,这是一个出于好奇的问题:
.NET v2中引入的泛型CreateInstance方法System.Activator对泛型参数没有类型约束,但在激活类型上需要默认构造函数,否则MissingMethodException抛出a.对我而言,这个方法似乎应该有类型约束
Activator.CreateInstance<T>() where T : new() {
...
}
Run Code Online (Sandbox Code Playgroud)
只是遗漏或潜伏在这里的一些轶事?
更新
正如所指出的,编译器不允许你编写
private T Create<T>() where T : struct, new()
error CS0451: The 'new()' constraint cannot be used with the 'struct' constraint
Run Code Online (Sandbox Code Playgroud)
但是,请参阅注释可以将结构用作指定new()约束的泛型方法的类型参数.在这种情况下,给定的答案似乎是不限制方法的唯一正当理由......
谢谢你看看这个!
我有点迷失方向让这个发生得最快.我有一大堆具有基本变量属性的对象(带有getter/setter),我需要在此列表中进行搜索,以查找列表中与给定参数匹配的对象
我已经找到了如何进行常规列表搜索但我需要,例如搜索为列表中的每个对象执行调用getName()的结果的值,并获取具有与我的输入匹配的结果的对象.
像下面的东西,第三个参数是方法调用的结果,第二个参数是我想要找到的.
int index = Collections.binarySearch(myList, "value", getName());
Run Code Online (Sandbox Code Playgroud)
任何建议表示赞赏
同
#include <iostream>
using namespace std;
int a = 1;
int main()
{
int a = 2;
if(true)
{
int a = 3;
cout << a
<< " " << ::a // Can I access a = 2 here?
<< " " << ::a << endl;
}
cout << a << " " << ::a << endl;
}
Run Code Online (Sandbox Code Playgroud)
有输出
3 1 1
2 1
Run Code Online (Sandbox Code Playgroud)
有没有办法在if语句中访问等于2的'a',其中'a'等于3,输出
3 2 1
2 1
Run Code Online (Sandbox Code Playgroud)
注:我知道这应该不会做(和代码不应该得到的地方,我要问的点).这个问题更" 可以做".
我有一个Windows应用程序计划每天运行,并由于以下日志在EventViewer中间歇性失败.
Faulting application name: MyApplication.exe, version: 1.0.0.0, time stamp: 0x4d54829a
Faulting module name: clr.dll, version: 4.0.30319.1, time stamp: 0x4ba21eeb
Exception code: 0xc0000005
Fault offset: 0x00000000000029e1
Faulting process id: 0xbb1c
Faulting application start time: 0x01cbd99223d8b4eb
Faulting application path: E:\MyApplication\MyApplication.exe
Faulting module path: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Report Id: 7e74ec7e-45a5-11e0-a95d-003048de380d
Run Code Online (Sandbox Code Playgroud)
在第二个EventViewer日志中,它说:
The process was terminated due to an internal error in the .NET Runtime at IP 000007FEF97329E1 (000007FEF9730000) with exit code 80131506.
Run Code Online (Sandbox Code Playgroud)
服务器是Win Server 2008 R2,应用程序使用.Net 4.0(您也可以在错误日志中看到).
应用程序密集使用多线程并从远程数据库读取并写入本地硬盘.
有关此问题的原因和任何帮助如何调查?我不知道它在应用程序的生命周期中失败了大约5-10个小时.
我是boost和c ++的新手,并且正在尝试将对象序列化为二进制,然后对其进行反序列化.
我正在使用示例中的类:http://en.highscore.de/cpp/boost/serialization.html
所以假设这是我尝试序列化的类:
class person
{
public:
person() { }
person(int age) : age_(age) { }
int age() const { return age_; }
private:
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive &ar, const unsigned int version)
{
ar & age_;
}
int age_;
};
Run Code Online (Sandbox Code Playgroud)
这是序列化代码:
const char * save(Object ss)
{
boost::archive::binary_oarchive oa(ss);
person p(31);
oa << p;
return ss.str().data();
}
Run Code Online (Sandbox Code Playgroud)
这是反序列化代码:
void load(const char * str)
{
stringstream s;
s << str;
boost::archive::binary_iarchive ia(s); …Run Code Online (Sandbox Code Playgroud) 我试图解决一个"经典"动态编程问题.问题是 - 给定一个数字作为输入,生成可能的嵌套条件.
编辑:正如下面的temp所指出的,我将首先尝试使用递归对其进行排序,然后尝试使用动态编程.
即.如果n = 3
O/p
((()))
()()()
(())()
()(())
(()())
Run Code Online (Sandbox Code Playgroud)
我对这个问题的处理方法基于两个规则.
从理论上讲,它们听起来是正确的,但它在下面的源头上是平坦的.请原谅硬编码.
编辑:我做了一些修改,并向解决方案移动了一英寸:)
#include <iostream>
#include <vector>
#include <string>
using namespace std;
void printPar(int l,int r,string s)
{
if(l > 3 || r > 3 || r >l)
return;
if(l==3 && r==3)
{
cout<<s<<endl;
return;
}
else
{
if((l<3))
{
s+="<";
l = l+1;
printPar(l,r,s);
}
if(r<3 && r < l)
{
s+=">";
r = r+1;
printPar(l,r,s);
}
// cout<<"Exiting "<<l<<" & "<<r<<" "<<s<<endl;
} …Run Code Online (Sandbox Code Playgroud) <Style x:Key="ContextMenuItemStyle" TargetType="{x:Type MenuItem}">
<Setter Property="Icon" Value="{Binding Icon}" />
<Setter Property="Header" Value="{Binding Text}" />
<Setter Property="ItemsSource" Value="{Binding Children}" />
<Setter Property="Command" Value="{Binding Command}" />
</Style>
Run Code Online (Sandbox Code Playgroud)
在这样的代码中设置它:
Uri refreshUri = new Uri("..\\Resources\\Refresh16.bmp",UriKind.Relative);
BitmapImage refreshIcon = new BitmapImage();
refreshIcon.UriSource = refreshUri;
Run Code Online (Sandbox Code Playgroud)
图标没有出现,任何线索?
我正在推出我的第一个游戏引擎:D.我现在正在处理纹理资源管理器,我想做得对.
以任何方式填充驱动程序支持的所有ActiveTexture单元是不是很糟糕?另一种方法是保存这些插槽,只在实际需要时设置纹理,代价是更多的glBindTexture调用.
每当PHP输出错误消息时,它会忽略css和设计精美的页面,方法是输出页面顶部的消息,删除任何阻碍它的方式.
例如
some code} else {
echo "error, please do something!";
Run Code Online (Sandbox Code Playgroud)
我如何得到(或很好地问)在我的CSS中已经存在的div中输出文本,以便它遵守该div附带的格式和对齐规则.