This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hello, I am having trouble committing a change to my database. I can successfully retrieve a user but I cannot update the user without getting the following.
Exception: {"The object [CtUser [Id=31, EntityState=Modified]] could not be saved because it is invalid.\r\n\r\nThe errors are:\r\n\r\nUrl is not a valid URI\r\n"} CODE: try { using (var uow = LightSpeedServices.Instance.GetUnitOfWork()) { CtUser userfromUOW = uow.Find<CtUser>(CtUser.Attribute("Id") == user.Id).First<CtUser>(); userfromUOW.Firstname= "Alexa"; //Without this line no exception uow.SaveChanges(); //(Exception on this line) } } catch (ValidationException ex) { MessageBox.Show(ex.ToString()); }
|
|
|
The reason you are getting this error is because the URL of your existing user does not match the URL syntax that is being validated for. If you are not intending to validate the Url, you should remove the validation from the model, you can do this in the designer by selecting the properties of the Url property and then set Validate Url to false. Alternatively, update the Url value to something which is a valid Url when saving. Validation is triggered when an entity has been added or updated and then is to be saved which is why you are not seeing this problem by just loading the user. Have a read through http://www.mindscape.co.nz/products/lightspeed/Help/Help%20Topics/LightSpeed/Validation.html for some more information about the validation in LightSpeed.
Jeremy |
|
|
To add to Jeremy's comment, it looks from your sample code as though you're not setting the Url property, so it's defaulting to null, which is considered an invalid URL. Jeremy's post shows you how to turn off URL validation on the Url property altogether, but if you want to keep URL validation but allow nulls, you can leave the validation in place but set IsRequired = False. To do this in a hand-written class, write your attribute as [ValidateUri(IsRequired = false)]. To do it in the designer, go into the LightSpeed Model Explorer (View > Other Windows > LightSpeed Model), expand the tree to find the Url property, expand its Validations folder, select the Uri Validation object, and set its Is Required to False. |
|