Print Page | Close Window

Why aren't [Required] fields verified?

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1405
Printed Date: 22-Sep-2025 at 4:19am


Topic: Why aren't [Required] fields verified?
Posted By: skingaby
Subject: Why aren't [Required] fields verified?
Date Posted: 31-Jul-2009 at 7:26am
When I run this test:
[TestMethod]

public void AddABogusDealNoLastUpdated()
{
    Deal deal = Deal.Create();
    deal.LastUpdateUser = "";
    //next line should throw verifier error without LastUpdateUser
    IdeaBlade.EntityModel.SaveResult result = deal.EntityAspect.EntityManager.SaveChanges();
}

The [Required] attribute on the LastUpdateUser property doesn't seem to be doing much.
My savehandler does this:
public void DomainModelEntityManager_Saving(object sender, IdeaBlade.EntityModel.EntitySavingEventArgs e)

{
    VerifierResultCollection allResults = new VerifierResultCollection();
    foreach (Entity item in e.Entities)
    {
        var itemResults = ((BaseEntity)item).VerifyInstance();
        foreach (var result in itemResults) { allResults.Add(result); }
    }
    if (!allResults.AreOk)
    {
        e.Cancel = true;
        VerifierResults = allResults;
    }
}

I have a verifier that checks something else and it causes the save to be canceled. I had assumed that the [Required] field being empty would be a problem, but instead I get an Oracle error:
IdeaBlade.EntityModel.EntityManagerSaveException: ORA-01400: cannot insert NULL into ("GCSD9"."DEAL"."LAST_UPDATE_USER")
ORA-06512: at line 4 ---> Devart.Data.Oracle.OracleException: ORA-01400: cannot insert NULL into ("GCSD9"."DEAL"."LAST_UPDATE_USER")
ORA-06512: at line 4.

Is there a way to verify that the [Required] fields are populated?



Replies:
Posted By: skingaby
Date Posted: 03-Aug-2009 at 8:19am
Does anyone have any ideas on this?


Posted By: eileenv
Date Posted: 05-Aug-2009 at 2:16pm
What does your Create method look like? Are you initializing any fields in there to null?


Posted By: skingaby
Date Posted: 10-Aug-2009 at 10:03am
Yes. I do. Here is the code:
public static Deal Create(User user)

{
     return (Deal)Create<Deal>(user);
}

protected static BaseEntity Create<T>(User user) where T : BaseEntity
{
     InitManager();
     T item = _manager.CreateEntity<T>();
     GetATemporaryKey(item);
     item.InitializeDefaults(user);
     AddToManager(item);
     return item;
}

protected override void InitializeDefaults(User user)
{
     this.EnteredBy = user.UserId;
     this.DateEntered = DateTime.Now;
     this.DateOfDeal = DateTime.Today;
     this.DealNumber = null;
     this.Promoted = false;
     this.SoftDeleted = false;
     this.DealTermsChanged = false;
     this.Delivered = false;
     this.FlowDateStart = DateTime.Today.AddDays(1);
     this.FlowDateEnd = DateTime.Today.AddWeekdays(1);
}


Posted By: eileenv
Date Posted: 10-Aug-2009 at 10:23am
Are you using .NET or DevForce validation? Are you decorating the property with a [Required] attribute (.NET's) or [RequiredValueVerifier()] (DevForce's)?


Posted By: skingaby
Date Posted: 11-Aug-2009 at 7:13am
I switched from .Net to IdeaBlade validation and the RequiredValueVerifier is now there and working. Thank you. That fixed it. My Test now passes:
[TestMethod]

[ExpectedException(typeof(IdeaBlade.Validation.VerifierResultException))]
public void AddABogusDealNoLastUpdated()
{
     Deal deal = Deal.GetASimpleBuyDeal();
     deal.LastUpdateUser = "";
     //next line should throw error without LastUpdateUser
     IdeaBlade.EntityModel.SaveResult result = deal.EntityAspect.EntityManager.SaveChanges();
}



Print Page | Close Window