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);
                }
            }
        }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