EntityDeveloper generates wrong foreign entity properties???

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
HCRoman
Posts: 55
Joined: Wed 12 Aug 2009 05:47

EntityDeveloper generates wrong foreign entity properties???

Post by HCRoman » Fri 23 Oct 2009 05:58

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

Fortis
Posts: 14
Joined: Sat 17 Oct 2009 23:35

Post by Fortis » Mon 26 Oct 2009 10:21

You can alter the template used for code generation. (Under templates in the entity developer).


Gruß

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Mon 26 Oct 2009 11:27

Thank you for the reprot, we are investigating the situation.
I will let you know about the results.

HCRoman
Posts: 55
Joined: Wed 12 Aug 2009 05:47

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

Post by HCRoman » Mon 26 Oct 2009 12:40

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

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Mon 26 Oct 2009 13:50

We have already implemented the new template engine.
It will be available in the upcoming Beta build of Entity Developer.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 03 Nov 2009 14:58

The Beta build with the new template engine is available.

HCRoman
Posts: 55
Joined: Wed 12 Aug 2009 05:47

Beta 535 tested

Post by HCRoman » Fri 06 Nov 2009 09:47

: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

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Tue 10 Nov 2009 10:30

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.

HCRoman
Posts: 55
Joined: Wed 12 Aug 2009 05:47

Templates

Post by HCRoman » Tue 10 Nov 2009 10:44

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

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 10 Nov 2009 12:07

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.

Post Reply