Description of navigation attributes in NOP

Source: Internet
Author: User

Take the following three tables as an example.

Specificationattribute corresponds to multiple specificationattributeoptions. Therefore, their relationship is one-to-many.

In specificationattribute. You must first define the specificationattributeoption field.

As shown below.

private ICollection<SpecificationAttributeOption> _specificationAttributeOptions;

After the field is defined. You can set the navigation relationship.

       /// <summary>        /// Gets or sets the specification attribute options        /// </summary>        public virtual ICollection<SpecificationAttributeOption> SpecificationAttributeOptions        {            get { return _specificationAttributeOptions ?? (_specificationAttributeOptions = new List<SpecificationAttributeOption>()); }            protected set { _specificationAttributeOptions = value; }        }
 
 
In specificationattributeoption, specificationattribute is one end.
Therefore, only one specificationattributeoption can be defined. Of course, specificationattributeid
The Code is as follows.
        /// <summary>        /// Gets or sets the specification attribute identifier        /// </summary>        public int SpecificationAttributeId { get; set; }

The navigation relationships are as follows:

        /// <summary>        /// Gets or sets the specification attribute        /// </summary>        public virtual SpecificationAttribute SpecificationAttribute { get; set; }

This completes the one-to-many relationship. The following is a summary: for a one-to-multiple relationship, multiple ends are defined

This is the definition field private icollection <t> _ xxxxxxxs;
Then define attributes
        /// <summary>        /// Gets or sets the product specification attribute        /// </summary>        public virtual ICollection<T> Ts        {            get { return _xxxxxxxxs ?? (_xxxxxxxxs  = new List<Ts>()); }            protected set { _xxxxxxxxs  = value; }        }

This completes the end-to-end. Multi-end definition at the first end.

 

 

At multiple ends, just define the ID of one end ..

        public int SpecificationAttributeOptionId { get; set; }         public virtual SpecificationAttributeOption SpecificationAttributeOption { get; set; }

 

OK. Finished

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.