- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
您将如何从业务逻辑层中的一个方法调用数据访问层中的多个方法,以便所有 SQL 命令都存在于一个 SQL 事务中?
每个 DAL 方法都可以从 BLL 中的其他地方单独调用,因此不能保证数据层方法始终是事务的一部分。我们需要此功能,因此如果数据库在长时间运行的过程中脱机,则不会提交。业务层根据之前每个调用的结果编排不同的数据层方法调用。我们只想在整个过程的最后提交(从业务层)。
最佳答案
好吧,首先,您必须遵守您在 BLL 中指定为单个方法的原子工作单元。这将(例如)创建客户、订单和订单项目。然后,您可以将所有这些整齐地包装在 TransactionScope using 语句中。 TransactionScope 是这里的 secret 武器。下面是一些代码,幸运的是我现在正在处理 :):
public static int InsertArtist(Artist artist)
{
if (artist == null)
throw new ArgumentNullException("artist");
int artistid = 0;
using (TransactionScope scope = new TransactionScope())
{
// insert the master Artist
/*
we plug the artistid variable into
any child instance where ArtistID is required
*/
artistid = SiteProvider.Artist.InsertArtist(new ArtistDetails(
0,
artist.BandName,
artist.DateAdded));
// insert the child ArtistArtistGenre
artist.ArtistArtistGenres.ForEach(item =>
{
var artistartistgenre = new ArtistArtistGenreDetails(
0,
artistid,
item.ArtistGenreID);
SiteProvider.Artist.InsertArtistArtistGenre(artistartistgenre);
});
// insert the child ArtistLink
artist.ArtistLinks.ForEach(item =>
{
var artistlink = new ArtistLinkDetails(
0,
artistid,
item.LinkURL);
SiteProvider.Artist.InsertArtistLink(artistlink);
});
// insert the child ArtistProfile
artist.ArtistProfiles.ForEach(item =>
{
var artistprofile = new ArtistProfileDetails(
0,
artistid,
item.Profile);
SiteProvider.Artist.InsertArtistProfile(artistprofile);
});
// insert the child FestivalArtist
artist.FestivalArtists.ForEach(item =>
{
var festivalartist = new FestivalArtistDetails(
0,
item.FestivalID,
artistid,
item.AvailableFromDate,
item.AvailableToDate,
item.DateAdded);
SiteProvider.Festival.InsertFestivalArtist(festivalartist);
});
BizObject.PurgeCacheItems(String.Format(ARTISTARTISTGENRE_ALL_KEY, String.Empty, String.Empty));
BizObject.PurgeCacheItems(String.Format(ARTISTLINK_ALL_KEY, String.Empty, String.Empty));
BizObject.PurgeCacheItems(String.Format(ARTISTPROFILE_ALL_KEY, String.Empty, String.Empty));
BizObject.PurgeCacheItems(String.Format(FESTIVALARTIST_ALL_KEY, String.Empty, String.Empty));
BizObject.PurgeCacheItems(String.Format(ARTIST_ALL_KEY, String.Empty, String.Empty));
// commit the entire transaction - all or nothing
scope.Complete();
}
return artistid;
}
希望您能理解要点。基本上,这是一个要么成功要么失败的工作,不管任何不同的数据库(即在上面的例子中,艺术家和艺术家艺术家类型可以托管在两个单独的数据库存储中,但 TransactionScope 不太关心这一点,它在 COM+ 级别工作并管理原子性它可以“看到”的范围)
希望对你有帮助
编辑:您可能会发现 TransactionScope 的初始调用(在应用程序启动时)可能会稍微引人注意(即在上面的示例中,如果是第一次调用,可能需要2-3 秒完成),但是,后续调用几乎是瞬时的(即通常为 250-750 毫秒)。简单的联系点交易与(笨拙的)替代方案之间的权衡减轻了(对我和我的客户而言)初始“加载”延迟。
只是想证明没有妥协就没有轻松(尽管在初始阶段)
关于c# - 从 BLL 中的一个方法跨越多个 DAL 方法的事务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/493649/
我有以下 StackedXYAreaChart: 如何让我的绘图从左到右一直延伸,以便图表和绘图的边界之间没有空白?谢谢! 最佳答案 createStackedAreaChart()方法创建一个具有
当您将一个从 MarshalByRefObject 继承的对象传递给另一个 AppDomain 时,创建它的 AppDomain 所诱导的 GC.Collect() 不会收集该对象,前提是该对象在 G
我有一个使用 DefaultTableModel 的 JTable,它会生成如下表: 但是我很好奇是否有一种好方法可以在交叉的单元格中创建箭头,如下例所示...... 这对我来说似乎很难。有什么方法可
我在一个 div 中有 3 个 span。 Title Someinfomation Toright 为了使 c 类垂直对齐,我必须使用 margin-top 来修复它然而,对于 IE
首先,我完全意识到这个问题已经被问过很多次了,但是我发现的每种方法似乎都已经过时了和/或所引用的链接已不复存在。 所以我想知道是否有一种方法可以使 JTable 中的特定行跨越所有列,就像一个忽略该列
我需要帮助来按照下图获取 Bootstrap 布局。我无法弄清楚如何让黄色条与 Bootstrap 容器的整个宽度一起显示,而不影响列在移动 View 上的堆叠方式(第二张图片)。 所以我不需要在移动
我有一个包含以下数据的集合 _id name type 1 Banana Fruit 2 Tomato Vegetable 3 Carrot Vegetable 4 Tom
我知道有很多这类问题,但我没有看到一个与我的标准足够相似的问题。所以我想请你帮忙。我拥有的字段只是时间类型的开始和结束。我不能在其中涉及任何具体日期。如果时间范围不超过一天的午夜,我将直接比较两个元组
我有一个包含许多数字列的数据框,第一列需要针对第二列进行回归,然后存储 Rsqr 值,然后第一列针对第三列,然后存储 Rsqr 值...等等.这样做直到第 n 列回归到第 1 列。 我希望结果是一个数
标题可能很隐晦,但这是我的问题。 我有一张一天的事件表(行程表)。每个条目(例如参观博物馆)都有 slot_start 和 slot_end 时间列。这是 24 小时格式,例如 13:00:00 -
这对我来说是一个大问题,我正在努力解决不同设备之间的缩放问题。如果我只有一个回显的乘数,那就太好了,除非可以使用 javascript 变量来代替宽度、高度、字体大小等值... 例如,stackexc
不必是表格也可以是 div。 我的图片有一些透明部分需要混合。上半部分需要与下半部分不同的背景颜色混合。 所以在我看来,表格有 2 行,其中一行有一种背景颜色,另一行有另一种背景颜色,但图像跨越两行。
我试图以这样一种方式将 span 与 div 一起使用,即最后一个 span 占据 div 的剩余宽度 dddd: ssss .data{width:100%;display:bl
我在跨共享库边界使用 libstdc++ 的 std::any 实现和 mingw 时偶然发现了一个问题。它会产生一个 std::bad_any_cast 显然不应该(我相信)。 我使用 mingw-
我正在从一张 1bpp 索引图像剪切并粘贴到一张新图像。 一切正常,直到起始像素是 8 的除数。在下面的代码中,步幅等于相对于矩形宽度的值,直到我达到字节边界。那么步幅等于整个页面的宽度。 var c
我目前有以下 SwiftUI View : HStack { ... VStack { TextField { ... } SecureField { ... } Bu
我想构建一个标准的 JTable,但所有行都分布在一个特定的列上。因此该列必须仅包含一个以 JTextPane 作为其渲染器的单元格。您知道任何简单的方法吗? 注意:不需要第三方软件。 谢谢。 最佳答
这个问题在这里已经有了答案: 关闭 12 年前。 Possible Duplicate: Auto-size dynamic text to fill fixed size container. 假
我有一个左浮动的 div 和它跨越左浮动的 div 之后的 div。 看这里http://www.kienitz.it/kienitz_cms/referenzen/ . 我想要这样:http://w
我在水平导航栏上有一个下 zipper 接,如下所示:
我是一名优秀的程序员,十分优秀!