0

I have an LLBLGen entity.

MyEntity{
    public Decimal Foo;    //Stored in database as a NOT NULL field
}
....
public void SomeMethod(){
    MyEntity entity = new MyEntity();  //on initial inspection Foo reads as "0"

    adapter.SaveEntity(entity);  //will throw exception, "Foo can't be assigned a NULL value"
                                 //but on debug inspection, Foo = 0

    entity.Foo = 14M;
    adapter.SaveEntity(entity);  //will save ok.
}

If I don't assign a value to a number, the debugger reads it as not null, however, it throws an exception telling me that it's actually NULL.

I was trusting LLBLgen to auto assign all variables a default value, but I can't be so sure now.

Anyone able to shed some light on this please. Thanks.

Craig
  • 381
  • 5
  • 22

1 Answers1

0

The LLBLGen Pro runtime doesn't assign default values automatically, however you can specify it as default constraints in your database.

You can check if a field has a value assigned by checking the 'Fields' collection on your entity:

bool isValueAssigned = myEntity.Fields[(int)MyFieldIndex.Foo].CurrentValue!=null;

Wiebe Tijsma
  • 10,173
  • 5
  • 52
  • 68
  • Is this the sort of thing that I should be using a factory to do, to initialise my entities for me? – Craig Jul 21 '12 at 06:54
  • That's a possibility, I normally like to override OnBeforeEntitySave in an entity's partial class for setting default values (things like created/modified date) or add default constraints to the database – Wiebe Tijsma Jul 23 '12 at 08:23