Banane wrote:
Otis wrote:
Use a template which you bind to the template ID Custom_EntityInitializationTemplate.
This template then should contain code which sets teh flags to false. By using that template, your generated code will have every entity have this setting set to the value you want. Please see the documentation: "Using the generated code - Adding your own code to the generated classes" to learn how to set this up.
.
Is the property to set will be <entity>ReturnsNewIfNotFound = false ??
No:
__fieldnameMappedOnRelation_ReturnsNewIfNotFound = false;
See template below.
here is the code for my activity entity....what do I have to change??
isNew ?
private void InitClassEmpty(IPropertyDescriptorFactory propertyDescriptorFactoryToUse, IEntityFactory entityFactoryToUse)
{
base.Fields = EntityFieldsFactory.CreateEntityFieldsObject(EXCOL.DAL.EntityType.ActivityEntity);
base.IsNew=true;
base.EntityFactoryToUse = entityFactoryToUse;
base.Validator = new ActivityValidator();
InitClassMembers(propertyDescriptorFactoryToUse, entityFactoryToUse);
}
Where 'stuff here' is mentioned, the include template is injected, so copy the following to a file and bind it to Custom_EntityInitializationTemplate in a custom template set. See the documentation how to bind that.
<[Foreach RelatedEntity ManyToOne CrLf]><[If Not MappedFieldRelationIsHidden]> _<[CaseCamel MappedFieldNameRelation]>ReturnsNewIfNotFound=false;<[EndIf]><[NextForeach]>
<[Foreach RelatedEntity OneToOne CrLf]><[If Not MappedFieldRelationIsHidden]> _<[CaseCamel MappedFieldNameRelation]>ReturnsNewIfNotFound=false;<[EndIf]><[NextForeach]>
this then will set the flags for ALL related 1:1 and m:1 entities to true, which means null is always returned
(edit)hmm. I discover an issue where InitClassMembers is called after this include template. InitClassMembers set the flags to true. This is only the case when you initialize an empty new entity:
CustomerEntity c = new CustomerEntity();
Not when you fetch an entity. I'm now fixing that.
(edit2): OK.
I'd like to ask you to download the new template archive from the customer area, which make sure the InitClassMembers() call is done BEFORE the init template include, so your init template 's code's work isn't overwritten by InitClassMembers.
This feature was meant to make life easier, to avoid null reference exceptions at runtime, but it turned out to be real nightmare. As I'm sick and tired of it now, I'll add the option to 1.0.2005.1 even if that will make the code's workings change by a switch of a preference setting. I mean, I never ever want threads like these pop up ever again:
http://forums.asp.net/1001945/ShowPost.aspx