Page 1 of 1

EntityDeveloper generates wrong foreign entity properties???

Posted: Fri 23 Oct 2009 05:58
by HCRoman
Hi devart team,

I was searching for the reason why i can not break a entity reference by assigning a null value to that property.

I compared the code, that is created by Microsoft and that from devart entity developer, an I found the solution.


Microsoft gfenerates no null value check in the entity property setter, only in the reference property, that I can also not understand.
(It seems to be regardless if the property is nullable or not...)


Microsoft generates for example:

Code: Select all

        /// 
        /// Es gibt keine Kommentare für Product im Schema.
        /// 
        [global::System.Data.Objects.DataClasses.EdmRelationshipNavigationPropertyAttribute("MiniNWModel", "ProductEntität1", "Product")]
        [global::System.Xml.Serialization.XmlIgnoreAttribute()]
        [global::System.Xml.Serialization.SoapIgnoreAttribute()]
        [global::System.Runtime.Serialization.DataMemberAttribute()]
        public Product Product
        {
            get
            {
                return ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference("MiniNWModel.ProductEntität1", "Product").Value;
            }
            set
            {

            
//here is no null value check!!!!


global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference("MiniNWModel.ProductEntität1", "Product").Value = value;
            }
        }
        /// 
        /// Es gibt keine Kommentare für Product im Schema.
        /// 
        [global::System.ComponentModel.BrowsableAttribute(false)]
        [global::System.Runtime.Serialization.DataMemberAttribute()]
        public global::System.Data.Objects.DataClasses.EntityReference ProductReference
        {
            get
            {
                return ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference("MiniNWModel.ProductEntität1", "Product");
            }
            set
            {
            if ((value != null))
                {
                    ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.InitializeRelatedReference("MiniNWModel.ProductEntität1", "Product", value);
                }
            }
        }

devart generates:

Code: Select all

        /// 
        /// There are no comments for Arztgruppe in the schema.
        /// 
        [global::System.Data.Objects.DataClasses.EdmRelationshipNavigationPropertyAttribute("RLV.EntityModel", "Arztgruppe_Arzt1", "ArztgruppeHw")]
        [global::System.Xml.Serialization.XmlIgnoreAttribute()]
        [global::System.Xml.Serialization.SoapIgnoreAttribute()]
        [global::System.Runtime.Serialization.DataMemberAttribute()]
        public Arztgruppe ArztgruppeHw
        {
            get
            {
                return ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference("RLV.EntityModel.Arztgruppe_Arzt1", "ArztgruppeHw").Value;
            }
            set
            {

//here is the null value check why?????

             if ((value != null))
                    ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference("RLV.EntityModel.Arztgruppe_Arzt1", "ArztgruppeHw").Value = value;
                }
            }
        }

        /// 
        /// There are no comments for Arztgruppe in the schema.
        /// 
        [global::System.ComponentModel.BrowsableAttribute(false)]
        [global::System.Runtime.Serialization.DataMemberAttribute()]
        public global::System.Data.Objects.DataClasses.EntityReference ArztgruppeHwReference
        {
            get
            {
                return ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference("RLV.EntityModel.Arztgruppe_Arzt1", "ArztgruppeHw");
            }
            set
            {
                if ((value != null))
                {
                    ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.InitializeRelatedReference("RLV.EntityModel.Arztgruppe_Arzt1", "ArztgruppeHw", value);
                }
            }
        }
I can not understand why this is so generated???
If you try manually to break the reference by using:

ArztgruppeHwReference.Value = null

all works as expected, the reference is resetted and a back reference is cleared.

It is not possible to data bind the entity reference via ComboBox and have one entry that clears the reference, the only way I have found is to bind to the PropertyReference.Value path and this is not transparent.

Can you explain why the devart developer generates the properties in this way and how can i change that, to have the same code like MS???

I would prefer that both properties have the possibility to break the reference, so my code would look like:

Code: Select all

       /// 
        /// There are no comments for Arztgruppe in the schema.
        /// 
        [global::System.Data.Objects.DataClasses.EdmRelationshipNavigationPropertyAttribute("RLV.EntityModel", "Arztgruppe_Arzt1", "ArztgruppeHw")]
        [global::System.Xml.Serialization.XmlIgnoreAttribute()]
        [global::System.Xml.Serialization.SoapIgnoreAttribute()]
        [global::System.Runtime.Serialization.DataMemberAttribute()]
        public Arztgruppe ArztgruppeHw
        {
            get
            {
                return ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference("RLV.EntityModel.Arztgruppe_Arzt1", "ArztgruppeHw").Value;
            }
            set
            { 

//no null check!!!!


 ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference("RLV.EntityModel.Arztgruppe_Arzt1", "ArztgruppeHw").Value = value;
            }
        }

        /// 
        /// There are no comments for Arztgruppe in the schema.
        /// 
        [global::System.ComponentModel.BrowsableAttribute(false)]
        [global::System.Runtime.Serialization.DataMemberAttribute()]
        public global::System.Data.Objects.DataClasses.EntityReference ArztgruppeHwReference
        {
            get
            {
                return ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference("RLV.EntityModel.Arztgruppe_Arzt1", "ArztgruppeHw");
            }
            set
            {
                if ((value != null))
                {
                    ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.InitializeRelatedReference("RLV.EntityModel.Arztgruppe_Arzt1", "ArztgruppeHw", value);
                }


// new else 
                else
                {
((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference("RLV.EntityModel.Arztgruppe_Arzt1", "ArztgruppeHw").Value = value;
                }
            }
        }

Thanks for any help

Roman

Posted: Mon 26 Oct 2009 10:21
by Fortis
You can alter the template used for code generation. (Under templates in the entity developer).


Gruß

Posted: Mon 26 Oct 2009 11:27
by AndreyR
Thank you for the reprot, we are investigating the situation.
I will let you know about the results.

Custom templates not working (Path/Name problem???)

Posted: Mon 26 Oct 2009 12:40
by HCRoman
Thanks to devart,

hopefully we can catch the problem and that with custom templates too!

Hi Fortis, My custom templates are also not work like in your last post!!!.
What a great solution if it does not work....???
:wink: :wink:

Roman

Posted: Mon 26 Oct 2009 13:50
by AndreyR
We have already implemented the new template engine.
It will be available in the upcoming Beta build of Entity Developer.

Posted: Tue 03 Nov 2009 14:58
by AndreyR
The Beta build with the new template engine is available.

Beta 535 tested

Posted: Fri 06 Nov 2009 09:47
by HCRoman
:D :D :D :D :D :D

Hi devart team,

I am verry happy to see the new generated code!

The default template does all I am expect.

Now we have one new thing.

Is it possible to hav a flag in the designer or a set of templates for generating all the setters with before checks, so that the value is only
set if it is different to the current one????
This avoids modified state entities without any changes!!!


like

Code: Select all

        /// 
        /// There are no comments for Arztid in the schema.
        /// 
        [global::System.Data.Objects.DataClasses.EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
        [global::System.Runtime.Serialization.DataMemberAttribute()]
        public long Arztid
        {
            get
            {
                long value = this._Arztid;
                OnGetArztid(ref value);
                return value;
            }
            set
            {
                this.OnArztidChanging(ref value);
if(this._Arztid != value)
{
                this.ReportPropertyChanging("Arztid");
                this._Arztid = global::System.Data.Objects.DataClasses.StructuralObject.SetValidValue(value);
                this.ReportPropertyChanged("Arztid");
                this.OnArztidChanged();
}
            }
        } 
same should be also possible for references

Code: Select all

 
      /// 
        /// There are no comments for Arztgruppe in the schema.
        /// 
        [global::System.Data.Objects.DataClasses.EdmRelationshipNavigationPropertyAttribute("EntityModel", "Arztgruppe_Arzt", "Arztgruppe")]
        [global::System.Xml.Serialization.XmlIgnoreAttribute()]
        [global::System.Xml.Serialization.SoapIgnoreAttribute()]
        [global::System.Runtime.Serialization.DataMemberAttribute()]
        public Arztgruppe Arztgruppe
        {
            get
            {
                return ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference("EntityModel.Arztgruppe_Arzt", "Arztgruppe").Value;
            }
            set
            {
				if (!Arztgruppe.ReferenceEquals(Arztgruppe, value))
				{
					((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference("EntityModel.Arztgruppe_Arzt", "Arztgruppe").Value = value;
				}
            }
        }

        /// 
        /// There are no comments for Arztgruppe in the schema.
        /// 
        [global::System.ComponentModel.BrowsableAttribute(false)]
        [global::System.Runtime.Serialization.DataMemberAttribute()]
        public global::System.Data.Objects.DataClasses.EntityReference ArztgruppeReference
        {
            get
            {
                return ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference("EntityModel.Arztgruppe_Arzt", "Arztgruppe");
            }
            set
            {
				if (!ArztgruppeReference.Equals(value))
				{
					if (value != null)
					{
						((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.InitializeRelatedReference("EntityModel.Arztgruppe_Arzt", "Arztgruppe", value);
					}
					else
					{
						((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference("EntityModel.Arztgruppe_Arzt", "Arztgruppe").Value = null;
					}
				}
            }
        }


Tnx


Roman

Posted: Tue 10 Nov 2009 10:30
by Shalex
Thank you for your suggestion. It seems to be reasonable. The suggested changes will be included in our templates in one of the next builds. At the moment you can easily change the existing templates to adapt them to the necessary code generation by editing the code of the
GenerateProperty method.

Templates

Posted: Tue 10 Nov 2009 10:44
by HCRoman
Hi Shalex,

there is another missing thing in the template...

All RelatedEnd-Properties are not generated with Property-Changing-Notifications so DataBinding should not be updated on changes for this Properties!!

So I extend my templates also with this notifications and the partial methods.

like

Code: Select all

        /// 
        /// There are no comments for Arztgruppe in the schema.
        /// 
        [global::System.Data.Objects.DataClasses.EdmRelationshipNavigationPropertyAttribute("EntityModel", "Arztgruppe_Arzt", "Arztgruppe")]
        [global::System.Xml.Serialization.XmlIgnoreAttribute()]
        [global::System.Xml.Serialization.SoapIgnoreAttribute()]
        [global::System.Runtime.Serialization.DataMemberAttribute()]
        public Arztgruppe Arztgruppe
        {
            get
            {
                return ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference("EntityModel.Arztgruppe_Arzt", "Arztgruppe").Value;
            }
            set
            {
				OnArztgruppeChanging(ref value);
                if(!Arztgruppe.ReferenceEquals(Arztgruppe, value))
                {
                    OnPropertyChanging("Arztgruppe");
                    ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference("EntityModel.Arztgruppe_Arzt", "Arztgruppe").Value = value;
                    OnPropertyChanged("Arztgruppe");
                    OnArztgruppeChanged();
                }
            }
        }
Roman

Posted: Tue 10 Nov 2009 12:07
by AndreyR
Thank you for sharing your knowledge.
In case you have more suggestions concerning either the templates or other functionality of
Entity Developer, feel free to post or send them to us.