New Posts New Posts RSS Feed: Latest Version Generated Code Bug?
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Latest Version Generated Code Bug?

 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: Latest Version Generated Code Bug?
    Posted: 17-Sep-2009 at 12:49pm
As a point of order, the bug with nullable types may well be a bug, but it is also a bug on our end because the fields are boolean but have not been marked as NOT NULL in the database when they should have been.
Thanks kimj, your responses are always quick and helpful.
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 17-Sep-2009 at 12:30pm
Re the exception - that would be a bug.   We do attempt conversion of the DefaultValue when we stuff it into the entity, and Convert.ChangeType is throwing because of the Nullable<Boolean>.   For now, DefaultValue won't work with nullable types other than string.  We'll add this to the defect list.  Thanks for reporting it.
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 17-Sep-2009 at 12:10pm

Re the first post - We take whatever is defined in the DefaultValue attribute for the property in the EDMX file, and don't validate its correctness or make it language-specific.  So, if you modify the EDMX to use DefaultValue="false" for these properties the code should generate correctly for C#.

Just saw your second post ...

Edited by kimj - 17-Sep-2009 at 12:11pm
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: 17-Sep-2009 at 11:34am
Also, I am getting this error when I try to run the app:

Assembly Initialization method GcsAg.DomainModel.Test.AssemblyInitialization.AssemblyInit threw exception. IdeaBlade.EntityModel.EntityServerException: IdeaBlade.EntityModel.EntityServerException: Error loading entity relations ---> IdeaBlade.Core.IdeaBladeException: Error loading entity relations ---> System.InvalidCastException: Invalid cast from 'System.Boolean' to 'System.Nullable`1[[System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'.. Aborting test execution.

System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider provider)
System.Boolean.System.IConvertible.ToType(Type type, IFormatProvider provider)
System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
IdeaBlade.EntityModel.DataEntityProperty.UpdateDefaultValue()
IdeaBlade.EntityModel.DataEntityProperty..ctor(Type entityType, String propertyName, Type dataType, Boolean isNullable, Boolean isPartOfKey, ConcurrencyStrategy concurrencyStrategy, Boolean isAutoIncrementing, VerificationSetterOptions verificationSetterOptions, Boolean isNativeProperty)
ctor(String propertyName, Boolean isNullable, Boolean isPartOfKey, ConcurrencyStrategy concurrencyStrategy, Boolean isAutoIncrementing, VerificationSetterOptions verificationSetterOptions, Boolean isNativeProperty)
ctor(String propertyName, Boolean isNullable, Boolean isPartOfKey, ConcurrencyStrategy concurrencyStrategy, Boolean isAutoIncrementing, VerificationSetterOptions verificationSetterOptions)
GcsAg.DomainModel.Contact..cctor() in C:\_dev\GcsAg090720\GcsAg.DomainModel\GcsAg.DomainModel.ServerModel.Designer.cs: line 16264
IdeaBlade.EntityModel.EntityServerProxy.CheckConnection(Exception e)
IdeaBlade.EntityModel.EntityServerProxy.Fetch(SessionBundle bundle, IEntityQuerySurrogate query)
IdeaBlade.EntityModel.EntityManager.ExecuteServerQuery(IEntityQuerySurrogate pEntityQuery)
IdeaBlade.EntityModel.EntityManager.HandleEntityServerException(Exception pException, Boolean pTryToHandle, PersistenceOperation pOperation)
IdeaBlade.EntityModel.EntityManager.ExecuteServerQuery(IEntityQuerySurrogate pEntityQuery)
IdeaBlade.EntityModel.EntityManager.ExecuteFetch(IEntityFinder finder)
IdeaBlade.EntityModel.EntityQueryFinder.Execute()
IdeaBlade.EntityModel.EntityManager.ExecuteQueryCore(IEntityQuery query, Boolean isAsync)
IdeaBlade.EntityModel.EntityManager.ExecuteQuery(IEntityQuery query)
GcsAg.DomainModel.DomainModelEntityManager.InitializeCache() in C:\_dev\GcsAg090720\GcsAg.DomainModel\DomainModelEntityManager.cs: line 235
GcsAg.DomainModel.DomainModelEntityManager.InitializeEntityManagerOnServer() in C:\_dev\GcsAg090720\GcsAg.DomainModel\DomainModelEntityManager.cs: line 44
GcsAg.DomainModel.DomainModelEntityManager.InitializeEntityManager() in C:\_dev\GcsAg090720\GcsAg.DomainModel\DomainModelEntityManager.cs: line 30
GcsAg.DomainModel.Test.AssemblyInitialization.AssemblyInit(TestContext context) in C:\_dev\GcsAg090720\GcsAg.DomainModel.Test\AssemblyInitialization.cs: line 17
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: 17-Sep-2009 at 11:20am
It seems the generated code has an invalid setting for the DefaultValue for boolean properties in C#:
    [Bindable(true, BindingDirection.TwoWay)]
    [Editable(true)]
    [Display(Name="Promoted", AutoGenerateField=true)]
    [IbVal.ValidateProperty]
    [IbVal.RequiredValueVerifier()]
    [IbCore.DBDataType(typeof(Boolean))]
    [DefaultValue(False)]
    [MsSer.DataMember]
    public Boolean Promoted {
       get { return PromotedEntityProperty.GetValue(this); }
       [global::System.Diagnostics.DebuggerNonUserCode]
       set { PromotedEntityProperty.SetValue(this, value); }
    }

Notice the upper case False. A lower case false works fine. A simple find and replace has fixed it for me. Am I doing something wrong though? Is my mapping file wrong somewhere? Thanks, Simon.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down