CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

ComponentModel.DataAnnotations - stopped working?

rated by 0 users
Answered (Verified) This post has 4 verified answers | 7 Replies | 1 Follower

Top 50 Contributor
157 Posts
Q Johnson posted on Thu, Sep 23 2010 2:17 PM

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.

Q Johnson

Answered (Verified) Verified Answer

Top 10 Contributor
9,269 Posts
Verified by Q Johnson

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).

Rocky

Top 50 Contributor
161 Posts
Verified by Q Johnson

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.

 

Don't forget to verify the post(s) that best answers your question!

.NET Developer @ http://www.sybiz.com.au

Top 10 Contributor
9,269 Posts
Verified by Q Johnson

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

Rocky

Top 10 Contributor
1,764 Posts
Verified by Q Johnson

HI,

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

Jonny Bekkum, Norway CslaContrib Coordinator

All Replies

Top 10 Contributor
9,269 Posts
Verified by Q Johnson

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).

Rocky

Top 50 Contributor
157 Posts

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>

Q Johnson
Top 50 Contributor
161 Posts
Verified by Q Johnson

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.

 

Don't forget to verify the post(s) that best answers your question!

.NET Developer @ http://www.sybiz.com.au

Top 10 Contributor
9,269 Posts
Verified by Q Johnson

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

Rocky

Top 50 Contributor
157 Posts

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>.

 

Q Johnson
Top 10 Contributor
1,764 Posts
Verified by Q Johnson

HI,

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

Jonny Bekkum, Norway CslaContrib Coordinator

Top 50 Contributor
157 Posts

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!!!

 

 

 

Q Johnson
Page 1 of 1 (8 items) | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems