ComponentModel.DataAnnotations - stopped working?

ComponentModel.DataAnnotations - stopped working?

Old forum URL: forums.lhotka.net/forums/t/9568.aspx


Q Johnson posted on Thursday, September 23, 2010

I've been having uneven (and now, none at all) success with these.

I've got all my properties decorated with the Required attribute and I call CheckRules at the end of my Child_Fetch routine.  I haven't added any Validation Rules because my understanding is that they are unnecessary for this simple kind of validation to work (and this is somewhat verified by my early testing).

When I first did this, my Parent Object's IsValid was set False and I was able to iterate the BrokenRules collection for all except the first member of the child collection (which actually had the most validation failures, oddly enough).  So I thought I was enjoying some real success and only needed to do a little tweaking. 

But I made some changes to my code generation template, and although the output looks good to my viewing, NO validation failure are being caught in spite of the fact that all four members of the collection have at least one problem.  Interrogation of the IsValid property for the parent and each child returns True every time.

So now I don't know why it won't work now OR why it DID work before.  Any ideas?

Thanks.

RockfordLhotka replied on Thursday, September 23, 2010

On thing to keep in mind is that the attributes do have to be merged into the CSLA business rules subsystem. This is automatically handled by the base AddBusinessRules() method, but if you override this method and don't call the base, then the attributes won't work as expected (or at all).

Q Johnson replied on Thursday, September 23, 2010

If I understand you correctly, as long as I am not overriding AddBussinessRules, this should be working, right?

I don't have a single line of code in that method.  Should I be calling the base explicitly? ( I wasn't doing that when this was briefly working.)

If it had NEVER worked, it wouldn't be nearly as frustrating! <g>

Marjon1 replied on Thursday, September 23, 2010

If in your template you have overridden AddBusinessRules, your first line should be MyBase.AddBusinessRules() otherwise you will run problems with the DataAnnotation rules not working. Don't forget your own base class for BusinssBase, if you have done anything in there as well.

 

RockfordLhotka replied on Friday, September 24, 2010

If you don't override the method, then it should work just fine.

Q Johnson replied on Friday, September 24, 2010

Unfortunately that isn't the case.  I am not overriding and it isn't working.

I'm pulling about 30 property values for the four EditableChild document objects that are pulled out of a database from various related tables by the query in my EditableRootList parent object. 

I'm marking ALL the properties as required.  And I'm calling CheckRules in the Child_Fetch routine after the values get loaded.

The first of the four documents is missing about 20 of the items.  The others are missing about half a dozen.

And yet ERL parent IsValid and so are each individual EC.  I can access the properties and determine that they are empty, but they don't trigger the creation of any BrokenRule objects, which I would just LOVE to display for the user so they can go back to the salt mines and re-work their data entry.

I'll keep slugging away.  But I'm sure hoping for some inspiration from you veterans of the CSLA 3.8.x world.  (Reminder info to save you from scrolling up: VS 2008, VB.NET, SQL 2008, CSLA 3.8.3, Win7 64-bit.

Have a great weekend.  If I solve this today, I will, too <g>.

 

JonnyBee replied on Friday, September 24, 2010

HI,

Can you post som code sample for us. Hard to figure out what is happening in your objects without seeing the code.

Q Johnson replied on Friday, September 24, 2010

I think I've got it now.  My Validation Rules section used to have the code in the method commented out but the declaration was still there!  I didn't realize that by just have a declaration of an empty method that I was overriding that base method.  When I commented out the declaration (actually someone showed me this) it all started working just fine.

So, as you all seem to have known somehow, I WAS overriding, even though I thought I wasn't.  I was telling the truth when I said I didn't have any code in the routine.  But I did have it declared. 

A buddy of mine calls these BPEs.  bone-headed programmer errors.

Thanks for following up and have a great weekend all!!!

 

 

 

Copyright (c) Marimer LLC