New Posts New Posts RSS Feed: Validation Upon Save
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Validation Upon Save

 Post Reply Post Reply
Author
jipock View Drop Down
Newbie
Newbie
Avatar

Joined: 08-Dec-2010
Location: Cherry Hill, NJ
Posts: 39
Post Options Post Options   Quote jipock Quote  Post ReplyReply Direct Link To This Post Topic: Validation Upon Save
    Posted: 08-Mar-2011 at 10:20am
Good Afternoon,
 
I'm attempting now to validate an entity upon save that is Property1 on a specific entity type is null then stop the save and throw an exception.
 
I'm not finding a good way to do this... I thought to look into the EntityServerSaveInterceptor, but ValidateSave() doesn't take parameters, nor do I find a way of grabbing the entities being saved (and manually loop through all of them). The entity itself does have PropertyInterceptors for individual properties (before Set, After Set, etc.), but I don't want to check it until Save time.
 
Any suggestions on this?
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 08-Mar-2011 at 4:47pm
Hi jipock,
 
Assuming that the entity type you are looking for is Employee, the Property is LastName, and you are validating only new entities:
 
protected override bool ValidateSave() {
  var em = EntityManager;
  var foundEntities = em.FindEntities(typeof(Employee), EntityState.Added);
 
  foreach (Employee entity in foundEntities.Cast<Object>().ToList()) {
  if (entity.LastName == null) {
    em.RemoveEntity(entity);
  }
  return base.ValidateSave();
}
 
Note that, back in the client, while the successfully saved entities were updated to EntityState.Unchanged, the "unsaved" entities still have EntityState.Added.
 
Silvio.


Edited by sbelini - 08-Mar-2011 at 5:21pm
Back to Top
jipock View Drop Down
Newbie
Newbie
Avatar

Joined: 08-Dec-2010
Location: Cherry Hill, NJ
Posts: 39
Post Options Post Options   Quote jipock Quote  Post ReplyReply Direct Link To This Post Posted: 09-Mar-2011 at 5:40am
Much thanks,  Silvio.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down