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
|
I have a client application that connects to a WCF service, and I reference the Model dll on the client side. The Entities defined by the LightSpeed ORM are sent back and forth over the wire between client and service. I would like to trim a string that can run really long in some cases so that it doesn't get kicked out by the Length validation on the server. I could bake a constant limit into the client code, but that means I have to manually keep the client and server code/database in synch... I thought I could use the Metadata library to accomplish this, but I don't see that property anywhere in EntityInfo. I know you can do this, as you provide a LightSpeedModelValidatorProvider for web clients, so how do I get to this information? Can you please provide or point me to some example code? I poked around for over an hour and found all kinds of interesting things getting carried around with my data, but no Length Validator... Thanks, Dave
|
|
|
Hmm, yes, we should probably add that information to the metadata. I'll see if we can get that done for you. In the meantime, a possible workaround is to call DataAnnotationBuilder.GetDataAnnotations(entityType, propertyName) to translate the LightSpeed validations to DataAnnotations validations (which is what the LightSpeedModelValidatorProvider does) and then look for StringLengthAttribute in the returned set. Obviously, this is a kludge, and we'll try to get you a more direct solution as soon as possible. |
|
|
Thanks! You guys are the greatest... I will try implementing the DataAnnotations kludge you suggest here, just to get more familiar with the process, but it would be much better to have the information in the metadata. Dave |
|
|
Hi Dave, The current nightly builds now make the Reflection.FieldInfo available from the Metadata.FieldInfo (via the new Field property). You can then use GetCustomAttributes to look for validation attributes. We did look at whether we could expose the validation rules more directly, but some of the properties you would need are currently internal. We'll keep this in mind for the future though. |
|
|
Thanks Ivan -- but I'm not sure if I don't know how to use it or if it's just not working. I get nothing back from the GetCustomAttributes() method. The field I am interested in is defined in the Model.cs file as: [ValidatePresence(AllowEmptyString=true)] var entityInfo = testRecord.EntityInfo(); var fieldInfo = entityInfo.Fields.Find(f => f.HumanName == "Failure Reason"); var customAttrs = fieldInfo.Field.GetCustomAttributes(false); |
|
|
Resharper tells you customAttrs is never used because you haven't yet written the code to use it. Intellisense says "when overridden" because the documentation was written for an abstract base class, probably MemberInfo. It is implemented. The attributeType argument is the type of the attribute, in your case typeof(ValidateLengthAttribute). (The boolean argument comes into play only in inheritance situations; don't worry about it.) Hence: if (fieldInfo.Field.IsDefined(typeof(ValidateLengthAttribute), false)) {
|
|
|
That worked! My apologies for not letting you know sooner. Thanks again for all the assistance you guys give so freely... Dave |
|