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