We've released a new version recently. Here are the changes we have made:
[main] Added constraint option allowing to skip the constraint if the field isn't changed
[main] DifferentialTuple.Merge() operation no longer causes StackOverflow exception
[main] Fixed certain cases of foreign key absence for reference fields of structures
[main] Fixed translation of enum value as default field value
[sqlserver] Fixed extraction of information about indexes from database
As usual you can download it from our official website or install it from Nuget library
Complete changes description is below.
New PropertyValidator option
We have added a new property called ValidateOnlyIfModified for the field constraints. The property as you have probably guessed allows to skip certain constraints on validation if field value wasn't changed. For example,
[HierarchyRoot]
public class User : Entity{
[Field, Key]
public int Id { get; private set; }
[Field(Length = 70)]
// this constraint will validate field value
// even if it is still
[NotNullOrEmptyConstraint]
public string FirstName { get; set; }
[Field(Length = 70)]
[NotNullOrEmptyConstraint]
public string FirstName { get; set; }
[Field(Length = 70)]
// this constraint will validate field value
// only the value is changed
[NotNullOrEmptyConstraint(ValidateOnlyIfModified = true)]
public string LastName { get; set; }
[Field(Length = 70, Nullable = true)]
public string HiddenComment { get; set;}
}
Now lets see how it works. Say, we want to add some comment to a user so we query the User entity and edit the HiddenComment field, the field without any validators, and don't change the rest of the fields like that:
[NotNullOrEmptyConstraint(ValidateOnlyIfModified = true)]
public string LastName { get; set; }
[Field(Length = 70, Nullable = true)]
public string HiddenComment { get; set;}
}
Now lets see how it works. Say, we want to add some comment to a user so we query the User entity and edit the HiddenComment field, the field without any validators, and don't change the rest of the fields like that:
using (var session = domain.OpenSession())
johnUser.HiddenComment = "He is the best";
// commit leads to validation
In this case, the constraint of the FirstName field will be triggered despite the field hasn't been changed. It is an example of constraints' regular behavior. More interestingly, the constraint of the LastName field will be skipped thanks to the new option.
Another case. We change the LastName field.
johnUser.LastName = "Brown";
// commit leads to validation
Here, both of the constraints will cause validation of their fields - the first constraint will be triggered because it has to do it every time and the second one - because the field value has been modified.
Need to say, an attempt to change the field value is more important than an actual value which was set for the field. Check the example below
johnUser.LastName = "Brown";
// commit leads to validation
The LastName field value will be validated despite the fact that the new value is actually the same as previous one. It happens because an entity registers for validation on set field value attempt and you should take this particularity into account.
Summing up all of the above, the new option will be helpful for those who for some reason don't want to validate untouched fields. Another possible case is when you are import some rows to DataObjects.net database and you are not completely sure the data is valid, with help of this option you will softly migrate data to valid state.
[Field]
[Field]
[HierarchyRoot]
[Field]
public class ExtendedQuantity : Quantity
public class Quantity : Structure
[Field]
the association between the InvoiceItem type and Measure type used to be skipped and it led to absence of foreign key in database. Such behavior was incorrect so we've fixed it and since this version such foreign keys will be built correctly.
There is no longer a problem with default value translation.
There was a possibility of an error on schema extraction as DataObjects.Net tried to extract indexes which are not supported. The problem could show up in SQL Server beginning from 2014 version. We forced unsupported indexes to be skipped on extraction. If you have some unsupported indexes e.g. ColumnsStore indexes, they will be skipped so you should control them by yourself.
using (var tx = session.OpenTransaction()) {
var johnUser = session.Query.All<User>()
.First(u => u.FirstName=="John");
johnUser.HiddenComment = "He is the best";
// commit leads to validation
tx.Complete();
}
Another case. We change the LastName field.
using (var session = domain.OpenSession())
using (var tx = session.OpenTransaction()) {
var johnUser = session.Query.All<User>()
.First(u => u.FirstName=="John");
johnUser.LastName = "Brown";
// commit leads to validation
tx.Complete();
}
Here, both of the constraints will cause validation of their fields - the first constraint will be triggered because it has to do it every time and the second one - because the field value has been modified.
Need to say, an attempt to change the field value is more important than an actual value which was set for the field. Check the example below
using (var session = domain.OpenSession())
using (var tx = session.OpenTransaction()) {
var johnUser = session.Query.All<User>()
.First(u => u.FirstName=="John" && u.LastName=="Brown");
johnUser.LastName = "Brown";
// commit leads to validation
tx.Complete();
}
Summing up all of the above, the new option will be helpful for those who for some reason don't want to validate untouched fields. Another possible case is when you are import some rows to DataObjects.net database and you are not completely sure the data is valid, with help of this option you will softly migrate data to valid state.
StackOverflowException on persist operation
Some of our customers faced with the exception, trying to save changes to storage. The error showed up on DifferentialTuple.Merge() operation. So if you have similar symptoms this may be your case. From this version the problem is fixed.Foreign key absence for reference fields of structures
In cases like below
[HierarchyRoot]
public class InvoiceItem : Entity
{
[Field]
public long Id { get; private set; }
[Field]
public Product Product { get; set; }
[Field]
// this field is important
public ExtendedQuantity Quantity { get; set; }
}
[HierarchyRoot]
public class Measure : Entity
{
[Field]
public int Id { get; private set; }
[Field]
public string Name { get; set; }
}
public class ExtendedQuantity : Quantity
{
//some other fields
}
public class Quantity : Structure
{
[Field]
public double Vaule { get; set; }
[Field]
public Measure Measure { get; set; }
}
Enum field default value translation
There were cases when FieldAttrubute.DefaultValue for inherited fields of enum type translated incorrectly. For example:
public enum ProductStage
{
//Some stages
}
[HierarchyRoot]
public class Product : Entity
{
[Key, Field]
public long Id { get; private set; }
[Field(DefaultValue = OneTwo.One)]
public ProductStage Stage { get; set; }
}
public class FinalProduct : Product
{
}
There is no longer a problem with default value translation.
Index related information extraction for MS SQL Server
There was a possibility of an error on schema extraction as DataObjects.Net tried to extract indexes which are not supported. The problem could show up in SQL Server beginning from 2014 version. We forced unsupported indexes to be skipped on extraction. If you have some unsupported indexes e.g. ColumnsStore indexes, they will be skipped so you should control them by yourself.
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThere are many freelancers who can help you with the problem. Cloud Freelancing has many freelancers with great expertise.
ReplyDeleteTotally wonderful to subscribe to this page. I am so glad to be a regular listener.
ReplyDeleteauto repair company
It's awesome. I want to read more
ReplyDeleteVery helpful. about us
ReplyDeleteOne of a kind. This must be shared and let's read more
ReplyDeleteThis is amazing!
ReplyDeleteBOOTS AND BEAUTY
Thank you for this info.
ReplyDeletehttps://deanhineslawyer.com/
Another possible case is when you are import some rows to DataObjects.net database and you are not completely sure the data is valid, with help of this option you will softly migrate data to valid state. fort worth internet marketing services
ReplyDeleteWould love to read more of this dataobjects.
ReplyDeleteTotally wonderful to subscribe to this page. I am so glad to be a regular listener. drywall hanging Chicago, Il
ReplyDeleteGlad to check this blog. https://www.foamprosboston.com/
ReplyDeleteWould this, in a way, help us make designs for our products digitally? Looking forward for your feedback. :)
ReplyDeleteheadstone engraving
Click Here
ReplyDeleteclick here if you want to know more about us.
ReplyDeleteThe mission of car rental service in Cancun is to help people pick the right rental car service. Before you book, they will show you everything you need to know. Our team is trying to do everything possible so that you will consider us the best car rental service for the day or long term. Go here to learn more about us.
ReplyDeleteGreat info! Keep on posting. Big thanks from https://www.devinealign.com/
ReplyDeleteWe also had a stackoverflow with DO5, code worked in DO4, but had a workaround which was to call Session.SaveChanges in a massive insert query, to avoid other errors. Removing Session.SaveChanges,Gutter Specialistsremoved the stackoverflow exception.
ReplyDeleteGreat work on this article. Thank you for sharing.
ReplyDeleteretaining walls on slopes
Great work.
ReplyDeletemold remediation near me
Nice! Thank you for this.
ReplyDeletehttps://www.aaplumbing.com/
Thanks for the information.
ReplyDeletecash for junk cars
This is interesting.
ReplyDeleteCable tray manufacturer
I find this blog interesting. www.treeservicecantonohio.net
ReplyDeleteTotally wonderful to subscribe to this page. I am so glad to be a regular listener. crawl spaces
ReplyDeleteI think I would be needing this in the future.
ReplyDeletemens best deodorant
I visited your official website and www.drywallelpaso.com was surprised to see all the topics that we can learn there. All the best!
ReplyDeleteI always visited your website. I learn a lot from this keep posting. auto repair parts
ReplyDeleteGreat post! It's clear and informative. Visit us
ReplyDeleteReally nice post Alexey Kulakov.
ReplyDeleteYou have a nice product! | NOVA Concreters Alexandria VA
ReplyDelete