Search code examples
llblgenpro

LLBLGen default variable field values reads not null but are null


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.


Solution

  • 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;