We have released a new version of DataObjects.Net
In the version following changes were performed:
[main] Fixed certain scenarios when In() or Contains() operations in query led to NullReferenceExecption exception
[main] Persist operation no longer breaks enumeration of EntitySet items.
Detailed explanation of these changes is in the post.
As usual you can get it from our website or install from Nuget library.
[TestFixture]
public class ContainsTest
{
// ...
// some other members
// ...
private static int StaticItemId = 1;
private int InstanceItemId = 1;
[Test]
public void MainTest()
{
using (var domain = Domain.Build(GetDomainConfiguration())
using (var session = domain.OpenSession())
using (var trasnaction = session.OpenTransaction()) {
var ids = new[] {1, 2};
// works fine
var count = session.Query.All<TestEntity>()
.Count(e => ids.Contains(InstanceItemId)));
// used to be a problem
var count = session.Query.All<TestEntity>()
.Count(e => ids.Contains(StaticItemId)));
}
}
}
Now both cases work fine.
using (var domain = Domain.Build(GetDomainConfiguration())
using (var session = domain.OpenSession())
using (var transaction = session.OpenTransaction()) {
//get order with some items
var order = session.Query.All<Order>().First();
// locally added item
order.Items.Add(new OrderItem());
foreach (var orderItems in order.Items) {
// there are no changes to the collection performed
// forces local changes to be saved to storage explicitly
session.SaveChanges();
}
}
And an example of implicit saving of changes
using (var domain = Domain.Build(GetDomainConfiguration())
using (var session = domain.OpenSession())
using (var transaction = session.OpenTransaction()) {
//get order with some items
var order = session.Query.All<Order>().First();
// locally added item
order.Items.Add(new OrderItem());
foreach (var orderItems in order.Items) {
// there are no changes to the collection performed
// implicit saving
var orderItemCount = session.Query.All<OrderItem>().Count();
}
}
Basically, an EntitySet<T> collection consists of three sets - the first set of items is saved to the database, the second set consists of locally added items and the third one is locally removed items. Two last sets store changes of collection between savings them to the storage. A persist operation (saving changes) merges all the three sets into the first one, which caused an exception during enumeration.
This merge mechanism was changed. Now only user changes can be the cause of enumeration termination. If a user adds or removes something from the EntitySet instance which is being currently enumerated it will break the enumeration. See example below:
using (var domain = Domain.Build(GetDomainConfiguration())
using (var session = domain.OpenSession())
using (var transaction = session.OpenTransaction()) {
//get order with some items
var order = session.Query.All<Order>().First();
// locally added item
order.Items.Add(new OrderItem());
foreach (var orderItems in order.Items) {
//we change contents of the EntitySet
order.Items.Add(new OrderItem());
}
}
Here, the EntitySet<Order> collection was modified during enumeration so it should be terminated.
Another case when user implicitly changes EntitySet is a paired association. For instance, for the model showed below
[HierarchyRoot]
public class Order : Entity
{
[Field, Key]
public long Id { get; private set; }
[Field]
public EntitySet<OrderItem> Items { get; private set; }
// some other fields
public Order(Session session)
: base(session)
{}
}
[HierarchyRoot]
public class OrderItem : Entity
{
[Field, Key]
public long Id { get; private set; }
[Field]
[Association(PairTo = "Items")]
public Order Order { get; set; }
//some other fields
public OrderItem(Session session)
: base(session)
{}
}
Order.Items and OrderItem.Order fields will remain in synchronized state. That cause modification of Items collection and if such thing happens during the collection enumeration an exception will show up. The code below is a great illustration.
using (var domain = Domain.Build(GetDomainConfiguration())
using (var session = Domain.OpenSession())
using (var transaction = session.OpenTransaction()) {
var order = session.Query.All<Order>().First();
var newOrder = new Order();
foreach (var orderItem in order.Items) {
// remove the orderItem from the Items collection
orderItem.Order = newOrder;
}
}
On the first iteration orderItem entity becomes removed from order.Items collection and added to newOrder.Items collection by setting orderItem.Order field. On the second iteration enumerator will detect the order.Items collection is changed and throw an exception.
So now EntitySet enumeration works as it is supposed to and causes no exception unless the collection has been changed by user.
In the version following changes were performed:
[main] Fixed certain scenarios when In() or Contains() operations in query led to NullReferenceExecption exception
[main] Persist operation no longer breaks enumeration of EntitySet items.
Detailed explanation of these changes is in the post.
As usual you can get it from our website or install from Nuget library.
NullReferenceException during query translation
Sometimes inclusion of a static fields in operations like In() or Contains() resulted in the exception. Instance fields are handled correctly though. For example,[TestFixture]
public class ContainsTest
{
// ...
// some other members
// ...
private static int StaticItemId = 1;
private int InstanceItemId = 1;
[Test]
public void MainTest()
{
using (var domain = Domain.Build(GetDomainConfiguration())
using (var session = domain.OpenSession())
using (var trasnaction = session.OpenTransaction()) {
var ids = new[] {1, 2};
// works fine
var count = session.Query.All<TestEntity>()
.Count(e => ids.Contains(InstanceItemId)));
// used to be a problem
var count = session.Query.All<TestEntity>()
.Count(e => ids.Contains(StaticItemId)));
}
}
}
Now both cases work fine.
Persist operation terminates EntitySet items enumeration
Saving local changes to storage while EntitySet<T> collection is being enumerated caused an exception due to the modification of collection. For instance,using (var domain = Domain.Build(GetDomainConfiguration())
using (var session = domain.OpenSession())
using (var transaction = session.OpenTransaction()) {
//get order with some items
var order = session.Query.All<Order>().First();
// locally added item
order.Items.Add(new OrderItem());
foreach (var orderItems in order.Items) {
// there are no changes to the collection performed
// forces local changes to be saved to storage explicitly
session.SaveChanges();
}
}
And an example of implicit saving of changes
using (var domain = Domain.Build(GetDomainConfiguration())
using (var session = domain.OpenSession())
using (var transaction = session.OpenTransaction()) {
//get order with some items
var order = session.Query.All<Order>().First();
// locally added item
order.Items.Add(new OrderItem());
foreach (var orderItems in order.Items) {
// there are no changes to the collection performed
// implicit saving
var orderItemCount = session.Query.All<OrderItem>().Count();
}
}
Basically, an EntitySet<T> collection consists of three sets - the first set of items is saved to the database, the second set consists of locally added items and the third one is locally removed items. Two last sets store changes of collection between savings them to the storage. A persist operation (saving changes) merges all the three sets into the first one, which caused an exception during enumeration.
This merge mechanism was changed. Now only user changes can be the cause of enumeration termination. If a user adds or removes something from the EntitySet instance which is being currently enumerated it will break the enumeration. See example below:
using (var domain = Domain.Build(GetDomainConfiguration())
using (var session = domain.OpenSession())
using (var transaction = session.OpenTransaction()) {
//get order with some items
var order = session.Query.All<Order>().First();
// locally added item
order.Items.Add(new OrderItem());
foreach (var orderItems in order.Items) {
//we change contents of the EntitySet
order.Items.Add(new OrderItem());
}
}
Here, the EntitySet<Order> collection was modified during enumeration so it should be terminated.
Another case when user implicitly changes EntitySet is a paired association. For instance, for the model showed below
[HierarchyRoot]
public class Order : Entity
{
[Field, Key]
public long Id { get; private set; }
[Field]
public EntitySet<OrderItem> Items { get; private set; }
// some other fields
public Order(Session session)
: base(session)
{}
}
[HierarchyRoot]
public class OrderItem : Entity
{
[Field, Key]
public long Id { get; private set; }
[Field]
[Association(PairTo = "Items")]
public Order Order { get; set; }
//some other fields
public OrderItem(Session session)
: base(session)
{}
}
Order.Items and OrderItem.Order fields will remain in synchronized state. That cause modification of Items collection and if such thing happens during the collection enumeration an exception will show up. The code below is a great illustration.
using (var domain = Domain.Build(GetDomainConfiguration())
using (var session = Domain.OpenSession())
using (var transaction = session.OpenTransaction()) {
var order = session.Query.All<Order>().First();
var newOrder = new Order();
foreach (var orderItem in order.Items) {
// remove the orderItem from the Items collection
orderItem.Order = newOrder;
}
}
On the first iteration orderItem entity becomes removed from order.Items collection and added to newOrder.Items collection by setting orderItem.Order field. On the second iteration enumerator will detect the order.Items collection is changed and throw an exception.
So now EntitySet enumeration works as it is supposed to and causes no exception unless the collection has been changed by user.
This comment has been removed by the author.
ReplyDeleteThanks for sharing an amazing post.
ReplyDeleteLogistics Company in Delhi
Shipping Company in India
Very nice post.
ReplyDeletewarehouse floor marking paint
best paint for floor marking
Nice post.
ReplyDeleteSEO Company in Delhi
SEO Service in Delhi
Great post..!
ReplyDeleteHp Designjet Printers in Delhi
hp designjet dealer in Delhi
Nice information. Thanks for sharing this informative blog with us. I really need this type of blog and I’m so lucky to found this...
ReplyDeletecctv camera dealers in patna
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThanks for the information you shared, this information is very helpful to me. I will often visit your blog.
ReplyDeleteProship là đơn vị cung cấp tới quý khách hàng dịch vụ vận tải nội địa, dịch vụ chuyển phát nhanh, dịch vụ ship cod, cho thuê xe tải,... uy tín, nhanh chóng và giá rẻ hiện nay tại TPHCM.
ReplyDeleteشركة تنظيف بالامارات
شركة تنظيف دبي
شركة تنظيف كنب بدبي بالبخار
شركة تنظيف سجاد بدبي
شركة تنظيف في ابوظبي
شركة تنظيف منازل فى العين
شركة تنظيف كنب في ابوظبي
شركة تنظيف كنب العين
Provide the Assignment Help online support service. Expert writers of US assignment who will help you by providing good high-quality essay help and other assignment assistance services.
ReplyDeleteFirstly, Thanks for all the useful insights. I would like to thank you for putting emphasis on how relevancy playing a big role in hosting industry. I appreciate your hard work. Keep posting new updates with us.
ReplyDeleteOffshore dedicated server
Beta Three was founded in 1988, Beta Three is professional audio manufacturer with R&D and producing;rich technicians and advanced R&D centre and www.stuccorepairlasvegasnv.com/
ReplyDeleteHey, I am Chang. I and my team are providing support for the users of HP printer related to issues that may occur while printer setup. In case you are also facing such issues. You will get the most appropriate solution by visiting HP Printer Offlineor you may connect to us by dialing our toll free number.
ReplyDeleteHP Envy 5540 Printer Offline
Thank you for posting this detailed content. Keep it up!
ReplyDeleteRegards | https://realsleep.com/
Thanks a lot for such amazing content. dns_probe_finished_nxdomain
ReplyDeleteerr_ssl_version_or_cipher_mismatch
Flatsome Review
wordpress dedicated hosting
fast vps hosting
managed woocommerce hosting
WordPress hosting for agencies
write for us
ReplyDeleteHello, If you want to buy your dream home without any brokeage then contact to our team and get exculsive offer.
ReplyDeleteBook Now why you are waiting for.
for more detail visit:- Best Residential Projects in Noida Extension
Hmm. This is definitely interesting.
ReplyDeletehttps://www.svgchevy.com/
I would love to know more about this.
ReplyDeletewww.carpetcleanercolumbia.com