New Posts New Posts RSS Feed: Checking an entity for errors
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Checking an entity for errors

 Post Reply Post Reply
Author
cjohnson84 View Drop Down
Groupie
Groupie


Joined: 24-Sep-2009
Location: Akron, Ohio
Posts: 44
Post Options Post Options   Quote cjohnson84 Quote  Post ReplyReply Direct Link To This Post Topic: Checking an entity for errors
    Posted: 06-Jul-2010 at 6:06am
I have bound an observable collection of entities retrieved from my database via my DevForce 2010 data model to a ComponentOne DataGrid.  I have the "Validation Attribute Mode" set to "DotNetValidation" in my data model.  This has allowed me to get validation working with the validation built into the grid.
 
When I edit the collection bound to the grid I see the validation errors.  We are allowing the users to modify the contents of the grid and then click a Save button which will commit the changes back to the database.
 
The issue I'm having is if the user clicks the Save button and validation errors exist (they are displayed visually) how do I check for the validation errors and not allow the commit operation?
 
I was thinking I could loop through the observable collection and check each entity to see if it has errors since ultimately the Entities inherit from INotifyDataErroInfo (in the EntityWrapper class).  I can't seem to find the implementation of the HasErrors property though and where this property of the interface is exposed.
 
I guess ultimately then my question is how do I check to see if an entity "HasErrors"?
 
 
 
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 06-Jul-2010 at 6:00pm
DevForce automatically runs instance verification, server-side, against all entities submitted for a save.

If you want to check client-side, you can do so in an EntityManager.Saving handler. In that, you have access to the collection of entities being saved, and can simply order instance verification against each.


_em1.Saving += new EventHandler<EntitySavingEventArgs>(_em1_Saving);
_em1.ExecuteQueryAsync<Customer>(customersQuery, GotCustomers, null);

...

void _em1_Saving(object sender, EntitySavingEventArgs e) {
foreach (Entity anEntity in e.Entities) {
    anEntity.EntityAspect.EntityManager.VerifierEngine.Execute(anEntity);
}
}


If any instance verification returns a VerifierResult that indicates a problem, you just set the Cancel property of the EntitySavingEventArgs object to true, and the save won't be submitted.


Edited by GregD - 06-Jul-2010 at 6:02pm
Back to Top
cjohnson84 View Drop Down
Groupie
Groupie


Joined: 24-Sep-2009
Location: Akron, Ohio
Posts: 44
Post Options Post Options   Quote cjohnson84 Quote  Post ReplyReply Direct Link To This Post Posted: 07-Jul-2010 at 11:24am
Thank you for clearing that up for me Greg!
Back to Top
jwooten View Drop Down
Newbie
Newbie


Joined: 31-Aug-2010
Location: Houston
Posts: 1
Post Options Post Options   Quote jwooten Quote  Post ReplyReply Direct Link To This Post Posted: 31-Aug-2010 at 3:31pm
I have the following scenario in a Silverlight 4 application using DevForce 2010...
 
I have 2 entities, say "Employee" and "Office"...  And "Employee" table has non-nullable column "PrimaryOfficeID" with foreign key relation to "OfficeID" column in "Office" table....
 
When I create new "Employee" entity in the application and then save it without assigning it a primary office... 
 
Why might it be that upon saving the new Employee entity that the result of executing verification on that entity (as shown above) does not reflect an error?
 
I assume this is because the PrimaryOffice property contains a null Office entity which is valid.  Is that correct?
 
If so, how do I make it so that attempting the save without assigning a primary office would cause this verification to fail? 
 
 
 
Back to Top
ting View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 27-Mar-2009
Location: San Francisco
Posts: 427
Post Options Post Options   Quote ting Quote  Post ReplyReply Direct Link To This Post Posted: 01-Sep-2010 at 7:02pm

Since the PrimaryOfficeID is non-nullable, it has to be assigned a default value on creation.  There is no required entity / foreign key validator in .NET or DevForce (perhaps we should create one), and the required field validator doesn't apply because the field is non-nullable.  So, there is nothing to say that the default value fails a verification check.

You can create an instance verifier on Employee that makes sure that:
  this.PrimaryOffice.EntityAspect.IsNullEntity == false

You can also create it as a property verifier on Employee.PrimaryOffice that does the same thing.

Here's the link to read about verification and see some samples:

If you have trouble, we can have someone write up a quick example.



Edited by ting - 01-Sep-2010 at 7:04pm
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down