EntitySpaces2009支持事件。
Transactions
You do not need to wrap saves on a single collection in a transaction. EntitySpaces does this for you, even if you have multiple inserts, updates, and deletes. Use transactions if you are saving two or more objects that need to rollback as a set in the event of a failure. EntitySpaces has two transaction models. esTransactionScope works with all supported databases. Set providerClass="DataProvider" in your app.config. TransactionScope uses the new .NET 2.0 TransactionScope class for databases that support it. Set providerClass="DataProviderEnterprise" in your app.config.
e.g.
OrdersCollection ordersCollection = new OrdersCollection();
Orders ordersEntity = new Orders();
OrderDetailsCollection orderDetailsCollection = new OrderDetailsCollection();
OrderDetails orderDetailsEntity = new OrderDetails();
ordersEntity = ordersCollection.AddNew();
ordersEntity.str.CustomerId = "3";
orderDetailsEntity = orderDetailsCollection.AddNew();
orderDetailsEntity.str.ProductId = "147";
orderDetailsEntity = orderDetailsCollection.AddNew();
orderDetailsEntity.OrderId = orderId;
orderDetailsEntity.str.ProductId = "255";
using(esTransactionScope scope = new esTransactionScope())
{
ordersCollection.Save();
//设置子对象的外键字段的值必须在父对象的主键值得到后才能设置,不然此值为null
orderDetailsEntity.OrderId = ordersEntity.Id.Value;
orderDetailsCollection.Save();
scope.Complete();
}
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步