New Posts New Posts RSS Feed: Why aren't [Required] fields verified?
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Why aren't [Required] fields verified?

 Post Reply Post Reply
Author
skingaby View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 23-Apr-2008
Location: United States
Posts: 146
Post Options Post Options   Quote skingaby Quote  Post ReplyReply Direct Link To This Post Topic: Why aren't [Required] fields verified?
    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?
Back to Top
skingaby View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 23-Apr-2008
Location: United States
Posts: 146
Post Options Post Options   Quote skingaby Quote  Post ReplyReply Direct Link To This Post Posted: 03-Aug-2009 at 8:19am
Does anyone have any ideas on this?
Back to Top
eileenv View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 15-Jun-2007
Location: United States
Posts: 68
Post Options Post Options   Quote eileenv Quote  Post ReplyReply Direct Link To This Post Posted: 05-Aug-2009 at 2:16pm
What does your Create method look like? Are you initializing any fields in there to null?
Back to Top
skingaby View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 23-Apr-2008
Location: United States
Posts: 146
Post Options Post Options   Quote skingaby Quote  Post ReplyReply Direct Link To This Post 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);
}
Back to Top
eileenv View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 15-Jun-2007
Location: United States
Posts: 68
Post Options Post Options   Quote eileenv Quote  Post ReplyReply Direct Link To This Post 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)?
Back to Top
skingaby View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 23-Apr-2008
Location: United States
Posts: 146
Post Options Post Options   Quote skingaby Quote  Post ReplyReply Direct Link To This Post 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();
}
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down