Subsonic 3 简单存储库和交易
这就是我到目前为止所拥有的。 是我做错了什么还是 3.0.0.3 中有错误?
var Repository = new SimpleRepository("DBConnectionName");
using (TransactionScope ts = new TransactionScope())
{
using (SharedDbConnectionScope scs = new SharedDbConnectionScope("connstring", "providerName"))
{
try
{
for (int i = 0; i < 5; i++)
{
Supplier s = new Supplier();
s.SupplierCode = i.ToString();
s.SupplierName = i.ToString();
Repository.Add<Supplier>(s);
}
ts.Complete();
}
catch
{
}
}
}
我在 SubSonic DbDataProvider 中遇到错误 公共 DbConnection CurrentSharedConnection { 获取{返回__sharedConnection; }
protected set
{
if(value == null)
{
__sharedConnection.Dispose();
ETC.. __sharedConnection == null :( 对象空引用异常 :(
So this is what I have so far. Am I doing something wrong or is there a bug in 3.0.0.3?
var Repository = new SimpleRepository("DBConnectionName");
using (TransactionScope ts = new TransactionScope())
{
using (SharedDbConnectionScope scs = new SharedDbConnectionScope("connstring", "providerName"))
{
try
{
for (int i = 0; i < 5; i++)
{
Supplier s = new Supplier();
s.SupplierCode = i.ToString();
s.SupplierName = i.ToString();
Repository.Add<Supplier>(s);
}
ts.Complete();
}
catch
{
}
}
}
I'm getting an error in SubSonic DbDataProvider
public DbConnection CurrentSharedConnection
{
get { return __sharedConnection; }
protected set
{
if(value == null)
{
__sharedConnection.Dispose();
etc..
__sharedConnection == null :( Object Null Reference Exception :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
终于自己解决了这个问题。 上述所有代码对我来说都不起作用(SubSonic 3.0.0.3,使用 SQLite),但添加
BeginTransaction()
使其按预期工作,大大加快了事务速度并回滚更新(如果有)出现异常情况。为了完整起见:
Access.Provider
是我的辅助类中的一个静态属性,它返回return SubSonic.DataProviders.ProviderFactory.GetProvider(ConnectionString, "System.Data.SQLite");
Finally solved this for myself. All of the above code does not work for me (SubSonic 3.0.0.3, using SQLite) but adding
BeginTransaction()
caused it to work as expected, greatly speeding up the transaction and rolling back the updates if any exceptions occur.For completeness:
Access.Provider
is a static property in a helper class for me that returnsreturn SubSonic.DataProviders.ProviderFactory.GetProvider(ConnectionString, "System.Data.SQLite");
也许切换 SharedDbConnectionScope 和 TransactionScope 可能会有所帮助。
Perhaps switching the SharedDbConnectionScope and TransactionScope around may help.
当设置迁移时会发生这种情况 - 在表迁移时,数据库连接将关闭。
尝试使用 SimpleRepositoryOptions.None 的 SimpleRepository。
不知道这是否是一个错误。 我认为事务不适用于 SimpleRepository,在事务中抛出异常时我总是保存一半的数据......也许它只适用于 ActiveRecord? 有人知道吗?
This will happen when Migration is set - On tablemigration the dbconnection will be closed.
Try the SimpleRepository with SimpleRepositoryOptions.None.
Don't know if this is a bug. I think the transactions don't work with SimpleRepository, I've always half of the data saved when throwing an exception in the transaction... perhaps it's only for ActiveRecord? Anybody knows?