News, examples, tips, ideas and plans.
Thoughts around ORM, .NET and SQL databases.

Thursday, February 15, 2018

DataObjects.Net 5.0.17 Beta 3

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.


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.

















80 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. 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...
    cctv camera dealers in patna

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Thanks for the information you shared, this information is very helpful to me. I will often visit your blog.
    Proship 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
  6. 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.

    ReplyDelete
  7. Firstly, 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.

    Offshore dedicated server

    ReplyDelete
  8. 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/

    ReplyDelete
  9. Hey, 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.
    HP Envy 5540 Printer Offline

    ReplyDelete
  10. Thank you for posting this detailed content. Keep it up!
    Regards | https://realsleep.com/

    ReplyDelete
  11. Hello, If you want to buy your dream home without any brokeage then contact to our team and get exculsive offer.
    Book Now why you are waiting for.
    for more detail visit:- Best Residential Projects in Noida Extension

    ReplyDelete
  12. Thank you for your sharing. Thanks to this blog I can learn more things. Expand your knowledge and abilities. Actually the article is very practical. For instant support related to AOL Desktop Gold Update Error then please contact our team for instant help.

    ReplyDelete
  13. I want to pay my gratitude to you for sharing such an exciting and informative blog. Now, I would like to induce your attention to one of the leading mobile app development company . which excels in providing a wide range of Android and iOS app development services at an affordable cost.

    ReplyDelete
  14. You got a really useful blog. I have been here reading for about an hour. I am a newbie and your success is very much an inspiration for me. For instant support related to QuickBooks Desktop Installation Errors please contact our technical expert for help related to QuickBooks.

    ReplyDelete
  15. I am reading a blog on this website for the first time and I would like to tell you that the quality of the content is up to the mark. It is very well written. Thank you so much for writing this blog and I will surely read all the blogs from now on. I also write blog and my latest blog is QuickBooks Express Web Connect Error

    ReplyDelete
  16. You are really doing a marvelous job and keep the good work up and you have really inspired me.
    We are telecasting Hindi Reality Tv Show Bigg boss 15 free.Visit us to watch online its all episodes.
    Zindagi mere ghar aana watch online
    Watch zindagi mere ghar aana live
    Zindagi mere ghar aana full episode

    ReplyDelete
  17. Yeh rishta kya kehlata hai is a hindi reality tv show. If you want to watch it's free episodes
    online or download it's hd episodes than visit here.Hindi Desi Serials will be telecasted live.
    Yeh rishta kya kehlata hai watch online
    Yeh rishta kya kehlata hai watch live
    Yeh rishta kya kehlata hai full episode

    ReplyDelete
  18. quickbooks error 15106 is a typical issue that happens because of difficulty in the update program. It ordinarily suggests that the update program has been upset prompting this unforeseen mistake. You might experience this blunder code on your screen while utilizing it. Relax, you can without much of a stretch fix this blunder with appropriate advances.

    ReplyDelete
  19. There a different variety of datasets available in the market. Each one has some unique identify and features Create an online tv channel

    ReplyDelete
  20. Online video platform providers help businesses and professionals to easily create and manage their video content on the world wide web.

    ReplyDelete
  21. The top online video platform owners have many reasons to provide esteemed services to their approached audience like video sharing, generating leads, building product awareness, marketing, and assisting with paid access facility for video streaming.

    ReplyDelete
  22. Secure Cloud Video Platform that has strict security standards and privacy regulations helps mitigate risks of hacking, piracy

    ReplyDelete
  23. https://vienthucung.com/ noi chia se tat tan tat nhung thong tin xoay quanh the gioi thu cung, vat nuoi hay các loai dong vat.

    ReplyDelete
  24. This was a great release. Thanks for sharing.
    Our site

    ReplyDelete
  25. concrete companies 13201 zip code object-relational mapper (ORM) and business logic layer (BLL) framework.

    ReplyDelete
  26. A great resource in learning programming. bathroom remodeling Finsbury Park

    ReplyDelete
  27. That cause modification of Items collection and if such thing happens during the collection enumeration an exception will show up.
    https://www.google.com/maps?cid=7103629497482529158&_ga=2.141440049.229652753.1638346905-1925002581.1635364277

    ReplyDelete
  28. Contribute to DataObjects-NET/dataobjects-net development by creating an account on GitHub.

    URL: https://www.overlandparkjunkremovalpros.com/

    ReplyDelete
  29. I found a way to work around a project I have been working on recently using the information here. Thank you so much.

    gocryptome.io

    ReplyDelete
  30. Phenol market - Phenol is a pungent natural mixture with the molecular formula C6H5OH and is also known as carbolic acid. Phenol is a chemical solvent extensively used in various places, such as chemistry, biology, and medical laboratories. Moreover, phenol exists in numerous consumer products that are swallowed or rubbed onto several body parts. These commodities include creams, ear and nose drops, cold sore lotions, mouthwashes, gargles, throat lozenges, and antiseptic lotions.

    ReplyDelete
  31. A persist operation (saving changes) merges all the three sets into the first one, which caused an exception during enumeration. auto glass shop

    ReplyDelete
  32. Such an informative site! Thanks for sharing this info. Keep on posting. https://www.bathroomremodelgreensboronc.com

    ReplyDelete
  33. Sometimes inclusion of a static fields in operations like In() or Contains() resulted in the exception. Instance fields are handled correctly though. call us

    ReplyDelete
  34. Hello! Just want to ask if is there any free version of this available?
    usps mail forwarding

    ReplyDelete
  35. Great information, thanks for this. It's a really big help. best regards from https://www.clevelandbathroomremodel.com

    ReplyDelete
  36. A persist operation (saving changes) merges all the three sets into the first one, which caused an exception during enumeration.
    French drain repair San Francisco California

    ReplyDelete
  37. First and foremost, thank you for all of your valuable insights. I'd want to thank you for emphasizing the importance of relevancy in the hosting market. I appreciate all of your efforts. Continue to share new updates with us. | See us

    ReplyDelete
  38. Thanks for sharing a great and wonderful information! I find my website far better than before in a short period of time. See my website now www.sandyspringsfencepros.com

    ReplyDelete
  39. Thank you for this information. Great work.
    Bathroom remodeling

    ReplyDelete
  40. In old times, books were uncommon and a couple of elites can approach books however presently in light of mechanical headway, everybody approaches schooling and data.
    get the assistance with https://trevorlofk068.wordpress.com/2022/09/14/enough-already-15-things-about-an-industry-report-revealed-that-78-of-organizations-saw-team-coaching-in-increasing-demand-were-tired-of-hearing/

    ReplyDelete
  41. Amazing article, Thanks for sharing this one. fencingdundee.co.uk/

    ReplyDelete
  42. Nice to visit such an informative blog. info

    ReplyDelete
  43. This comment has been removed by the author.

    ReplyDelete
  44. Thanks for sharing this information. Keep on posting. info

    ReplyDelete
  45. Love your website. Keep up the good work. ReadMore: Kashmir Tour Packages

    ReplyDelete
  46. It's great to have a new version. Thanks. SEO for Video

    ReplyDelete
  47. DataObjects.Net is a persistence and object-relational mapping framework for the Microsoft .NET. It allows developers to define persistent objects as well as business logic directly in C#, Visual Basic or F#. https://www.iowacityconcretecontractors.com/

    ReplyDelete
  48. These are the things we need to really learn more about.

    https://luminas.com/clinical-study/

    ReplyDelete
  49. Now only user changes can be the cause of enumeration termination.

    Joana | concrete expert

    ReplyDelete
  50. Thanks for sharing so nice information....its a amazing work as well as idea. Kudos! Rick from house cleaning, looking forward to see more.

    ReplyDelete
  51. Thanks for the sharing the useful information. This post is very amazing and useful. You are also read more then click here Online tuition for hindi. Thank You!

    ReplyDelete
  52. Very much appreciated. Thank you for this excellent article. Keep posting!
    Fence service Little Rock

    ReplyDelete
  53. Thank you for providing this information. Visit us for Getting ICSE Online Tuition at Affordable prices.

    ReplyDelete
  54. Thanks for sharing such a useful information. It is very helpful article. Very informative blog.
    Tree Removal in Calgary Ab

    ReplyDelete
  55. very informative article!!! thank you so much!

    Red Deer Concrete

    ReplyDelete
  56. Your teaching help us excel in this field and help me find God. All the best!

    ReplyDelete