惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 【当耐特】
Help Net Security
Help Net Security
P
Proofpoint News Feed
J
Java Code Geeks
爱范儿
爱范儿
Last Week in AI
Last Week in AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Full Disclosure
Google DeepMind News
Google DeepMind News
H
Help Net Security
G
Google Developers Blog
Jina AI
Jina AI
Vercel News
Vercel News
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
Lohrmann on Cybersecurity
S
Schneier on Security
Microsoft Azure Blog
Microsoft Azure Blog
IT之家
IT之家
Security Archives - TechRepublic
Security Archives - TechRepublic
阮一峰的网络日志
阮一峰的网络日志
N
News and Events Feed by Topic
GbyAI
GbyAI
B
Blog
O
OpenAI News
博客园_首页
Cisco Talos Blog
Cisco Talos Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Hacker News: Ask HN
Hacker News: Ask HN
TaoSecurity Blog
TaoSecurity Blog
腾讯CDC
MongoDB | Blog
MongoDB | Blog
M
MIT News - Artificial intelligence
C
Cybersecurity and Infrastructure Security Agency CISA
Cyberwarzone
Cyberwarzone
Webroot Blog
Webroot Blog
Simon Willison's Weblog
Simon Willison's Weblog
Y
Y Combinator Blog
C
Cisco Blogs
A
Arctic Wolf
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Exploit Database - CXSecurity.com
Security Latest
Security Latest
AI
AI
W
WeLiveSecurity
aimingoo的专栏
aimingoo的专栏
The Register - Security
The Register - Security
Project Zero
Project Zero
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
Netflix TechBlog - Medium
Blog — PlanetScale
Blog — PlanetScale

博客园 - LutzMark

charles4抓https请求的注意事项,补充iphone7(ios10系统)无法解密ssl问题 XCode设置自己windows习惯的快捷键(比如Home、End键) MVC项目中ExecutionTimeout不生效的解决方案 Delegate与Event的区别 坑爹的MSN登录错误80072745 Linq的sum函数InvalidOperationException异常解决办法 LINQ to SQL 外键约束的插入及获取主表标识列等问题 Flex中的 for in 与 for each in - LutzMark Flex的DataGrid将水平分隔线设为虚线 - LutzMark - 博客园 解决Flex的DataGrid控件中ItemRender随Scrollbar的滚动发生UI重绘问题 - LutzMark - 博客园 去除ColumnChart自带的阴影效果 - LutzMark - 博客园 IIS7中配置WebOrb支持RTMPT 使用DataAdpater自动批量更新DataSet中的数据到数据库 委托的Invoke 和 BeginInvoke 与Control的Invoke和BeginInvoke(转-因为写得很好) 控制台测试异步委托 一篇好文,以在迷茫时阅读 驳《IT开发工程师的悲哀》 钢板与表针 不用临时变量,只用11个字符交换两个变量的值——窥视C#编译原理的冰山一角
LINQ to SQL自定义映射表关系(1:N or 1:1)
LutzMark · 2010-03-08 · via 博客园 - LutzMark

以Northwind库为例,新建LINQ TO SQL Classes,我们将表Suppliers和Products拖进新建的dbml文件设计界面。

   默认情况下,IDE自动生成的映射关系为1:N.即Cardinality属性为OneToMany即1:N。

如果我们想改为1:1则可选中表关系(图中空心实心箭头),修改Cardinality属性为OneToOne。

但是IDE会报错:Error 1 Cannot create an association "Supplier_Product". Properties do not have matching types: "SupplierID", "SupplierID".  

这个错误说明主表主键和从表的外键字段类型不一致,检查发现果然是Products表的外键字段SupplierID为可空类型而主表Suppliers的主键字段为不可空类型。

修改dbml中Products表的SupplierID的Nullable属性为False,然后修改Cardinality属性为OneToOne,成功!

1:N的自动生成映射类:

   using System.Data.Linq;
    using System.Data.Linq.Mapping;
    using System.Data;
    using System.Collections.Generic;
    using System.Reflection;
    using System.Linq;
    using System.Linq.Expressions;
    using System.ComponentModel;
    using System;


    [System.Data.Linq.Mapping.DatabaseAttribute(Name = "Northwind")]
    public partial class DataClasses1DataContext : System.Data.Linq.DataContext
    {

        private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();

        #region Extensibility Method Definitions
        partial void OnCreated();
        partial void InsertProduct(Product instance);
        partial void UpdateProduct(Product instance);
        partial void DeleteProduct(Product instance);
        partial void InsertSupplier(Supplier instance);
        partial void UpdateSupplier(Supplier instance);
        partial void DeleteSupplier(Supplier instance);
        #endregion

        public DataClasses1DataContext() :
            base(global::System.Configuration.ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString, mappingSource)
        {
            OnCreated();
        }

        public DataClasses1DataContext(string connection) :
            base(connection, mappingSource)
        {
            OnCreated();
        }

        public DataClasses1DataContext(System.Data.IDbConnection connection) :
            base(connection, mappingSource)
        {
            OnCreated();
        }

        public DataClasses1DataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
            base(connection, mappingSource)
        {
            OnCreated();
        }

        public DataClasses1DataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
            base(connection, mappingSource)
        {
            OnCreated();
        }

        public System.Data.Linq.Table<Product> Products
        {
            get
            {
                return this.GetTable<Product>();
            }
        }

        public System.Data.Linq.Table<Supplier> Suppliers
        {
            get
            {
                return this.GetTable<Supplier>();
            }
        }
    }

    [Table(Name = "dbo.Products")]
    public partial class Product : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private int _ProductID;

        private string _ProductName;

        private System.Nullable<int> _SupplierID;

        private System.Nullable<int> _CategoryID;

        private string _QuantityPerUnit;

        private System.Nullable<decimal> _UnitPrice;

        private System.Nullable<short> _UnitsInStock;

        private System.Nullable<short> _UnitsOnOrder;

        private System.Nullable<short> _ReorderLevel;

        private bool _Discontinued;

        private EntityRef<Supplier> _Supplier;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnProductIDChanging(int value);
        partial void OnProductIDChanged();
        partial void OnProductNameChanging(string value);
        partial void OnProductNameChanged();
        partial void OnSupplierIDChanging(System.Nullable<int> value);
        partial void OnSupplierIDChanged();
        partial void OnCategoryIDChanging(System.Nullable<int> value);
        partial void OnCategoryIDChanged();
        partial void OnQuantityPerUnitChanging(string value);
        partial void OnQuantityPerUnitChanged();
        partial void OnUnitPriceChanging(System.Nullable<decimal> value);
        partial void OnUnitPriceChanged();
        partial void OnUnitsInStockChanging(System.Nullable<short> value);
        partial void OnUnitsInStockChanged();
        partial void OnUnitsOnOrderChanging(System.Nullable<short> value);
        partial void OnUnitsOnOrderChanged();
        partial void OnReorderLevelChanging(System.Nullable<short> value);
        partial void OnReorderLevelChanged();
        partial void OnDiscontinuedChanging(bool value);
        partial void OnDiscontinuedChanged();
        #endregion

        public Product()
        {
            this._Supplier = default(EntityRef<Supplier>);
            OnCreated();
        }

        [Column(Storage = "_ProductID", AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public int ProductID
        {
            get
            {
                return this._ProductID;
            }
            set
            {
                if ((this._ProductID != value))
                {
                    this.OnProductIDChanging(value);
                    this.SendPropertyChanging();
                    this._ProductID = value;
                    this.SendPropertyChanged("ProductID");
                    this.OnProductIDChanged();
                }
            }
        }

        [Column(Storage = "_ProductName", DbType = "NVarChar(40) NOT NULL", CanBeNull = false)]
        public string ProductName
        {
            get
            {
                return this._ProductName;
            }
            set
            {
                if ((this._ProductName != value))
                {
                    this.OnProductNameChanging(value);
                    this.SendPropertyChanging();
                    this._ProductName = value;
                    this.SendPropertyChanged("ProductName");
                    this.OnProductNameChanged();
                }
            }
        }

        [Column(Storage = "_SupplierID", DbType = "Int")]
        public System.Nullable<int> SupplierID
        {
            get
            {
                return this._SupplierID;
            }
            set
            {
                if ((this._SupplierID != value))
                {
                    if (this._Supplier.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnSupplierIDChanging(value);
                    this.SendPropertyChanging();
                    this._SupplierID = value;
                    this.SendPropertyChanged("SupplierID");
                    this.OnSupplierIDChanged();
                }
            }
        }

        [Column(Storage = "_CategoryID", DbType = "Int")]
        public System.Nullable<int> CategoryID
        {
            get
            {
                return this._CategoryID;
            }
            set
            {
                if ((this._CategoryID != value))
                {
                    this.OnCategoryIDChanging(value);
                    this.SendPropertyChanging();
                    this._CategoryID = value;
                    this.SendPropertyChanged("CategoryID");
                    this.OnCategoryIDChanged();
                }
            }
        }

        [Column(Storage = "_QuantityPerUnit", DbType = "NVarChar(20)")]
        public string QuantityPerUnit
        {
            get
            {
                return this._QuantityPerUnit;
            }
            set
            {
                if ((this._QuantityPerUnit != value))
                {
                    this.OnQuantityPerUnitChanging(value);
                    this.SendPropertyChanging();
                    this._QuantityPerUnit = value;
                    this.SendPropertyChanged("QuantityPerUnit");
                    this.OnQuantityPerUnitChanged();
                }
            }
        }

        [Column(Storage = "_UnitPrice", DbType = "Money")]
        public System.Nullable<decimal> UnitPrice
        {
            get
            {
                return this._UnitPrice;
            }
            set
            {
                if ((this._UnitPrice != value))
                {
                    this.OnUnitPriceChanging(value);
                    this.SendPropertyChanging();
                    this._UnitPrice = value;
                    this.SendPropertyChanged("UnitPrice");
                    this.OnUnitPriceChanged();
                }
            }
        }

        [Column(Storage = "_UnitsInStock", DbType = "SmallInt")]
        public System.Nullable<short> UnitsInStock
        {
            get
            {
                return this._UnitsInStock;
            }
            set
            {
                if ((this._UnitsInStock != value))
                {
                    this.OnUnitsInStockChanging(value);
                    this.SendPropertyChanging();
                    this._UnitsInStock = value;
                    this.SendPropertyChanged("UnitsInStock");
                    this.OnUnitsInStockChanged();
                }
            }
        }

        [Column(Storage = "_UnitsOnOrder", DbType = "SmallInt")]
        public System.Nullable<short> UnitsOnOrder
        {
            get
            {
                return this._UnitsOnOrder;
            }
            set
            {
                if ((this._UnitsOnOrder != value))
                {
                    this.OnUnitsOnOrderChanging(value);
                    this.SendPropertyChanging();
                    this._UnitsOnOrder = value;
                    this.SendPropertyChanged("UnitsOnOrder");
                    this.OnUnitsOnOrderChanged();
                }
            }
        }

        [Column(Storage = "_ReorderLevel", DbType = "SmallInt")]
        public System.Nullable<short> ReorderLevel
        {
            get
            {
                return this._ReorderLevel;
            }
            set
            {
                if ((this._ReorderLevel != value))
                {
                    this.OnReorderLevelChanging(value);
                    this.SendPropertyChanging();
                    this._ReorderLevel = value;
                    this.SendPropertyChanged("ReorderLevel");
                    this.OnReorderLevelChanged();
                }
            }
        }

        [Column(Storage = "_Discontinued", DbType = "Bit NOT NULL")]
        public bool Discontinued
        {
            get
            {
                return this._Discontinued;
            }
            set
            {
                if ((this._Discontinued != value))
                {
                    this.OnDiscontinuedChanging(value);
                    this.SendPropertyChanging();
                    this._Discontinued = value;
                    this.SendPropertyChanged("Discontinued");
                    this.OnDiscontinuedChanged();
                }
            }
        }

        [Association(Name = "Supplier_Product", Storage = "_Supplier", ThisKey = "SupplierID", OtherKey = "SupplierID", IsForeignKey = true)]
        public Supplier Supplier
        {
            get
            {
                return this._Supplier.Entity;
            }
            set
            {
                Supplier previousValue = this._Supplier.Entity;
                if (((previousValue != value)
                            || (this._Supplier.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._Supplier.Entity = null;
                        previousValue.Products.Remove(this);
                    }
                    this._Supplier.Entity = value;
                    if ((value != null))
                    {
                        value.Products.Add(this);
                        this._SupplierID = value.SupplierID;
                    }
                    else
                    {
                        this._SupplierID = default(Nullable<int>);
                    }
                    this.SendPropertyChanged("Supplier");
                }
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

    [Table(Name = "dbo.Suppliers")]
    public partial class Supplier : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private int _SupplierID;

        private string _CompanyName;

        private string _ContactName;

        private string _ContactTitle;

        private string _Address;

        private string _City;

        private string _Region;

        private string _PostalCode;

        private string _Country;

        private string _Phone;

        private string _Fax;

        private string _HomePage;

        private EntitySet<Product> _Products;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnSupplierIDChanging(int value);
        partial void OnSupplierIDChanged();
        partial void OnCompanyNameChanging(string value);
        partial void OnCompanyNameChanged();
        partial void OnContactNameChanging(string value);
        partial void OnContactNameChanged();
        partial void OnContactTitleChanging(string value);
        partial void OnContactTitleChanged();
        partial void OnAddressChanging(string value);
        partial void OnAddressChanged();
        partial void OnCityChanging(string value);
        partial void OnCityChanged();
        partial void OnRegionChanging(string value);
        partial void OnRegionChanged();
        partial void OnPostalCodeChanging(string value);
        partial void OnPostalCodeChanged();
        partial void OnCountryChanging(string value);
        partial void OnCountryChanged();
        partial void OnPhoneChanging(string value);
        partial void OnPhoneChanged();
        partial void OnFaxChanging(string value);
        partial void OnFaxChanged();
        partial void OnHomePageChanging(string value);
        partial void OnHomePageChanged();
        #endregion

        public Supplier()
        {
            this._Products = new EntitySet<Product>(new Action<Product>(this.attach_Products), new Action<Product>(this.detach_Products));
            OnCreated();
        }

        [Column(Storage = "_SupplierID", AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public int SupplierID
        {
            get
            {
                return this._SupplierID;
            }
            set
            {
                if ((this._SupplierID != value))
                {
                    this.OnSupplierIDChanging(value);
                    this.SendPropertyChanging();
                    this._SupplierID = value;
                    this.SendPropertyChanged("SupplierID");
                    this.OnSupplierIDChanged();
                }
            }
        }

        [Column(Storage = "_CompanyName", DbType = "NVarChar(40) NOT NULL", CanBeNull = false)]
        public string CompanyName
        {
            get
            {
                return this._CompanyName;
            }
            set
            {
                if ((this._CompanyName != value))
                {
                    this.OnCompanyNameChanging(value);
                    this.SendPropertyChanging();
                    this._CompanyName = value;
                    this.SendPropertyChanged("CompanyName");
                    this.OnCompanyNameChanged();
                }
            }
        }

        [Column(Storage = "_ContactName", DbType = "NVarChar(30)")]
        public string ContactName
        {
            get
            {
                return this._ContactName;
            }
            set
            {
                if ((this._ContactName != value))
                {
                    this.OnContactNameChanging(value);
                    this.SendPropertyChanging();
                    this._ContactName = value;
                    this.SendPropertyChanged("ContactName");
                    this.OnContactNameChanged();
                }
            }
        }

        [Column(Storage = "_ContactTitle", DbType = "NVarChar(30)")]
        public string ContactTitle
        {
            get
            {
                return this._ContactTitle;
            }
            set
            {
                if ((this._ContactTitle != value))
                {
                    this.OnContactTitleChanging(value);
                    this.SendPropertyChanging();
                    this._ContactTitle = value;
                    this.SendPropertyChanged("ContactTitle");
                    this.OnContactTitleChanged();
                }
            }
        }

        [Column(Storage = "_Address", DbType = "NVarChar(60)")]
        public string Address
        {
            get
            {
                return this._Address;
            }
            set
            {
                if ((this._Address != value))
                {
                    this.OnAddressChanging(value);
                    this.SendPropertyChanging();
                    this._Address = value;
                    this.SendPropertyChanged("Address");
                    this.OnAddressChanged();
                }
            }
        }

        [Column(Storage = "_City", DbType = "NVarChar(15)")]
        public string City
        {
            get
            {
                return this._City;
            }
            set
            {
                if ((this._City != value))
                {
                    this.OnCityChanging(value);
                    this.SendPropertyChanging();
                    this._City = value;
                    this.SendPropertyChanged("City");
                    this.OnCityChanged();
                }
            }
        }

        [Column(Storage = "_Region", DbType = "NVarChar(15)")]
        public string Region
        {
            get
            {
                return this._Region;
            }
            set
            {
                if ((this._Region != value))
                {
                    this.OnRegionChanging(value);
                    this.SendPropertyChanging();
                    this._Region = value;
                    this.SendPropertyChanged("Region");
                    this.OnRegionChanged();
                }
            }
        }

        [Column(Storage = "_PostalCode", DbType = "NVarChar(10)")]
        public string PostalCode
        {
            get
            {
                return this._PostalCode;
            }
            set
            {
                if ((this._PostalCode != value))
                {
                    this.OnPostalCodeChanging(value);
                    this.SendPropertyChanging();
                    this._PostalCode = value;
                    this.SendPropertyChanged("PostalCode");
                    this.OnPostalCodeChanged();
                }
            }
        }

        [Column(Storage = "_Country", DbType = "NVarChar(15)")]
        public string Country
        {
            get
            {
                return this._Country;
            }
            set
            {
                if ((this._Country != value))
                {
                    this.OnCountryChanging(value);
                    this.SendPropertyChanging();
                    this._Country = value;
                    this.SendPropertyChanged("Country");
                    this.OnCountryChanged();
                }
            }
        }

        [Column(Storage = "_Phone", DbType = "NVarChar(24)")]
        public string Phone
        {
            get
            {
                return this._Phone;
            }
            set
            {
                if ((this._Phone != value))
                {
                    this.OnPhoneChanging(value);
                    this.SendPropertyChanging();
                    this._Phone = value;
                    this.SendPropertyChanged("Phone");
                    this.OnPhoneChanged();
                }
            }
        }

        [Column(Storage = "_Fax", DbType = "NVarChar(24)")]
        public string Fax
        {
            get
            {
                return this._Fax;
            }
            set
            {
                if ((this._Fax != value))
                {
                    this.OnFaxChanging(value);
                    this.SendPropertyChanging();
                    this._Fax = value;
                    this.SendPropertyChanged("Fax");
                    this.OnFaxChanged();
                }
            }
        }

        [Column(Storage = "_HomePage", DbType = "NText", UpdateCheck = UpdateCheck.Never)]
        public string HomePage
        {
            get
            {
                return this._HomePage;
            }
            set
            {
                if ((this._HomePage != value))
                {
                    this.OnHomePageChanging(value);
                    this.SendPropertyChanging();
                    this._HomePage = value;
                    this.SendPropertyChanged("HomePage");
                    this.OnHomePageChanged();
                }
            }
        }

        [Association(Name = "Supplier_Product", Storage = "_Products", ThisKey = "SupplierID", OtherKey = "SupplierID")]
        public EntitySet<Product> Products
        {
            get
            {
                return this._Products;
            }
            set
            {
                this._Products.Assign(value);
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void attach_Products(Product entity)
        {
            this.SendPropertyChanging();
            entity.Supplier = this;
        }

        private void detach_Products(Product entity)
        {
            this.SendPropertyChanging();
            entity.Supplier = null;
        }
    }

1:1的自动生成映射类:

  using System.Data.Linq;
    using System.Data.Linq.Mapping;
    using System.Data;
    using System.Collections.Generic;
    using System.Reflection;
    using System.Linq;
    using System.Linq.Expressions;
    using System.ComponentModel;
    using System;


    [System.Data.Linq.Mapping.DatabaseAttribute(Name = "Northwind")]
    public partial class DataClasses1DataContext : System.Data.Linq.DataContext
    {

        private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();

        #region Extensibility Method Definitions
        partial void OnCreated();
        partial void InsertSupplier(Supplier instance);
        partial void UpdateSupplier(Supplier instance);
        partial void DeleteSupplier(Supplier instance);
        partial void InsertProduct(Product instance);
        partial void UpdateProduct(Product instance);
        partial void DeleteProduct(Product instance);
        #endregion

        public DataClasses1DataContext() :
            base(global::System.Configuration.ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString, mappingSource)
        {
            OnCreated();
        }

        public DataClasses1DataContext(string connection) :
            base(connection, mappingSource)
        {
            OnCreated();
        }

        public DataClasses1DataContext(System.Data.IDbConnection connection) :
            base(connection, mappingSource)
        {
            OnCreated();
        }

        public DataClasses1DataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
            base(connection, mappingSource)
        {
            OnCreated();
        }

        public DataClasses1DataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
            base(connection, mappingSource)
        {
            OnCreated();
        }

        public System.Data.Linq.Table<Supplier> Suppliers
        {
            get
            {
                return this.GetTable<Supplier>();
            }
        }

        public System.Data.Linq.Table<Product> Products
        {
            get
            {
                return this.GetTable<Product>();
            }
        }
    }

    [Table(Name = "dbo.Suppliers")]
    public partial class Supplier : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private int _SupplierID;

        private string _CompanyName;

        private string _ContactName;

        private string _ContactTitle;

        private string _Address;

        private string _City;

        private string _Region;

        private string _PostalCode;

        private string _Country;

        private string _Phone;

        private string _Fax;

        private string _HomePage;

        private EntityRef<Product> _Products;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnSupplierIDChanging(int value);
        partial void OnSupplierIDChanged();
        partial void OnCompanyNameChanging(string value);
        partial void OnCompanyNameChanged();
        partial void OnContactNameChanging(string value);
        partial void OnContactNameChanged();
        partial void OnContactTitleChanging(string value);
        partial void OnContactTitleChanged();
        partial void OnAddressChanging(string value);
        partial void OnAddressChanged();
        partial void OnCityChanging(string value);
        partial void OnCityChanged();
        partial void OnRegionChanging(string value);
        partial void OnRegionChanged();
        partial void OnPostalCodeChanging(string value);
        partial void OnPostalCodeChanged();
        partial void OnCountryChanging(string value);
        partial void OnCountryChanged();
        partial void OnPhoneChanging(string value);
        partial void OnPhoneChanged();
        partial void OnFaxChanging(string value);
        partial void OnFaxChanged();
        partial void OnHomePageChanging(string value);
        partial void OnHomePageChanged();
        #endregion

        public Supplier()
        {
            this._Products = default(EntityRef<Product>);
            OnCreated();
        }

        [Column(Storage = "_SupplierID", AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public int SupplierID
        {
            get
            {
                return this._SupplierID;
            }
            set
            {
                if ((this._SupplierID != value))
                {
                    this.OnSupplierIDChanging(value);
                    this.SendPropertyChanging();
                    this._SupplierID = value;
                    this.SendPropertyChanged("SupplierID");
                    this.OnSupplierIDChanged();
                }
            }
        }

        [Column(Storage = "_CompanyName", DbType = "NVarChar(40) NOT NULL", CanBeNull = false)]
        public string CompanyName
        {
            get
            {
                return this._CompanyName;
            }
            set
            {
                if ((this._CompanyName != value))
                {
                    this.OnCompanyNameChanging(value);
                    this.SendPropertyChanging();
                    this._CompanyName = value;
                    this.SendPropertyChanged("CompanyName");
                    this.OnCompanyNameChanged();
                }
            }
        }

        [Column(Storage = "_ContactName", DbType = "NVarChar(30)")]
        public string ContactName
        {
            get
            {
                return this._ContactName;
            }
            set
            {
                if ((this._ContactName != value))
                {
                    this.OnContactNameChanging(value);
                    this.SendPropertyChanging();
                    this._ContactName = value;
                    this.SendPropertyChanged("ContactName");
                    this.OnContactNameChanged();
                }
            }
        }

        [Column(Storage = "_ContactTitle", DbType = "NVarChar(30)")]
        public string ContactTitle
        {
            get
            {
                return this._ContactTitle;
            }
            set
            {
                if ((this._ContactTitle != value))
                {
                    this.OnContactTitleChanging(value);
                    this.SendPropertyChanging();
                    this._ContactTitle = value;
                    this.SendPropertyChanged("ContactTitle");
                    this.OnContactTitleChanged();
                }
            }
        }

        [Column(Storage = "_Address", DbType = "NVarChar(60)")]
        public string Address
        {
            get
            {
                return this._Address;
            }
            set
            {
                if ((this._Address != value))
                {
                    this.OnAddressChanging(value);
                    this.SendPropertyChanging();
                    this._Address = value;
                    this.SendPropertyChanged("Address");
                    this.OnAddressChanged();
                }
            }
        }

        [Column(Storage = "_City", DbType = "NVarChar(15)")]
        public string City
        {
            get
            {
                return this._City;
            }
            set
            {
                if ((this._City != value))
                {
                    this.OnCityChanging(value);
                    this.SendPropertyChanging();
                    this._City = value;
                    this.SendPropertyChanged("City");
                    this.OnCityChanged();
                }
            }
        }

        [Column(Storage = "_Region", DbType = "NVarChar(15)")]
        public string Region
        {
            get
            {
                return this._Region;
            }
            set
            {
                if ((this._Region != value))
                {
                    this.OnRegionChanging(value);
                    this.SendPropertyChanging();
                    this._Region = value;
                    this.SendPropertyChanged("Region");
                    this.OnRegionChanged();
                }
            }
        }

        [Column(Storage = "_PostalCode", DbType = "NVarChar(10)")]
        public string PostalCode
        {
            get
            {
                return this._PostalCode;
            }
            set
            {
                if ((this._PostalCode != value))
                {
                    this.OnPostalCodeChanging(value);
                    this.SendPropertyChanging();
                    this._PostalCode = value;
                    this.SendPropertyChanged("PostalCode");
                    this.OnPostalCodeChanged();
                }
            }
        }

        [Column(Storage = "_Country", DbType = "NVarChar(15)")]
        public string Country
        {
            get
            {
                return this._Country;
            }
            set
            {
                if ((this._Country != value))
                {
                    this.OnCountryChanging(value);
                    this.SendPropertyChanging();
                    this._Country = value;
                    this.SendPropertyChanged("Country");
                    this.OnCountryChanged();
                }
            }
        }

        [Column(Storage = "_Phone", DbType = "NVarChar(24)")]
        public string Phone
        {
            get
            {
                return this._Phone;
            }
            set
            {
                if ((this._Phone != value))
                {
                    this.OnPhoneChanging(value);
                    this.SendPropertyChanging();
                    this._Phone = value;
                    this.SendPropertyChanged("Phone");
                    this.OnPhoneChanged();
                }
            }
        }

        [Column(Storage = "_Fax", DbType = "NVarChar(24)")]
        public string Fax
        {
            get
            {
                return this._Fax;
            }
            set
            {
                if ((this._Fax != value))
                {
                    this.OnFaxChanging(value);
                    this.SendPropertyChanging();
                    this._Fax = value;
                    this.SendPropertyChanged("Fax");
                    this.OnFaxChanged();
                }
            }
        }

        [Column(Storage = "_HomePage", DbType = "NText", UpdateCheck = UpdateCheck.Never)]
        public string HomePage
        {
            get
            {
                return this._HomePage;
            }
            set
            {
                if ((this._HomePage != value))
                {
                    this.OnHomePageChanging(value);
                    this.SendPropertyChanging();
                    this._HomePage = value;
                    this.SendPropertyChanged("HomePage");
                    this.OnHomePageChanged();
                }
            }
        }

        [Association(Name = "Supplier_Product", Storage = "_Products", ThisKey = "SupplierID", OtherKey = "SupplierID", IsUnique = true, IsForeignKey = false)]
        public Product Products
        {
            get
            {
                return this._Products.Entity;
            }
            set
            {
                Product previousValue = this._Products.Entity;
                if (((previousValue != value)
                            || (this._Products.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._Products.Entity = null;
                        previousValue.Supplier = null;
                    }
                    this._Products.Entity = value;
                    if ((value != null))
                    {
                        value.Supplier = this;
                    }
                    this.SendPropertyChanged("Products");
                }
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

    [Table(Name = "dbo.Products")]
    public partial class Product : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private int _ProductID;

        private string _ProductName;

        private int _SupplierID;

        private System.Nullable<int> _CategoryID;

        private string _QuantityPerUnit;

        private System.Nullable<decimal> _UnitPrice;

        private System.Nullable<short> _UnitsInStock;

        private System.Nullable<short> _UnitsOnOrder;

        private System.Nullable<short> _ReorderLevel;

        private bool _Discontinued;

        private EntityRef<Supplier> _Supplier;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnProductIDChanging(int value);
        partial void OnProductIDChanged();
        partial void OnProductNameChanging(string value);
        partial void OnProductNameChanged();
        partial void OnSupplierIDChanging(int value);
        partial void OnSupplierIDChanged();
        partial void OnCategoryIDChanging(System.Nullable<int> value);
        partial void OnCategoryIDChanged();
        partial void OnQuantityPerUnitChanging(string value);
        partial void OnQuantityPerUnitChanged();
        partial void OnUnitPriceChanging(System.Nullable<decimal> value);
        partial void OnUnitPriceChanged();
        partial void OnUnitsInStockChanging(System.Nullable<short> value);
        partial void OnUnitsInStockChanged();
        partial void OnUnitsOnOrderChanging(System.Nullable<short> value);
        partial void OnUnitsOnOrderChanged();
        partial void OnReorderLevelChanging(System.Nullable<short> value);
        partial void OnReorderLevelChanged();
        partial void OnDiscontinuedChanging(bool value);
        partial void OnDiscontinuedChanged();
        #endregion

        public Product()
        {
            this._Supplier = default(EntityRef<Supplier>);
            OnCreated();
        }

        [Column(Storage = "_ProductID", AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public int ProductID
        {
            get
            {
                return this._ProductID;
            }
            set
            {
                if ((this._ProductID != value))
                {
                    this.OnProductIDChanging(value);
                    this.SendPropertyChanging();
                    this._ProductID = value;
                    this.SendPropertyChanged("ProductID");
                    this.OnProductIDChanged();
                }
            }
        }

        [Column(Storage = "_ProductName", DbType = "NVarChar(40) NOT NULL", CanBeNull = false)]
        public string ProductName
        {
            get
            {
                return this._ProductName;
            }
            set
            {
                if ((this._ProductName != value))
                {
                    this.OnProductNameChanging(value);
                    this.SendPropertyChanging();
                    this._ProductName = value;
                    this.SendPropertyChanged("ProductName");
                    this.OnProductNameChanged();
                }
            }
        }

        [Column(Storage = "_SupplierID", DbType = "Int")]
        public int SupplierID
        {
            get
            {
                return this._SupplierID;
            }
            set
            {
                if ((this._SupplierID != value))
                {
                    if (this._Supplier.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnSupplierIDChanging(value);
                    this.SendPropertyChanging();
                    this._SupplierID = value;
                    this.SendPropertyChanged("SupplierID");
                    this.OnSupplierIDChanged();
                }
            }
        }

        [Column(Storage = "_CategoryID", DbType = "Int")]
        public System.Nullable<int> CategoryID
        {
            get
            {
                return this._CategoryID;
            }
            set
            {
                if ((this._CategoryID != value))
                {
                    this.OnCategoryIDChanging(value);
                    this.SendPropertyChanging();
                    this._CategoryID = value;
                    this.SendPropertyChanged("CategoryID");
                    this.OnCategoryIDChanged();
                }
            }
        }

        [Column(Storage = "_QuantityPerUnit", DbType = "NVarChar(20)")]
        public string QuantityPerUnit
        {
            get
            {
                return this._QuantityPerUnit;
            }
            set
            {
                if ((this._QuantityPerUnit != value))
                {
                    this.OnQuantityPerUnitChanging(value);
                    this.SendPropertyChanging();
                    this._QuantityPerUnit = value;
                    this.SendPropertyChanged("QuantityPerUnit");
                    this.OnQuantityPerUnitChanged();
                }
            }
        }

        [Column(Storage = "_UnitPrice", DbType = "Money")]
        public System.Nullable<decimal> UnitPrice
        {
            get
            {
                return this._UnitPrice;
            }
            set
            {
                if ((this._UnitPrice != value))
                {
                    this.OnUnitPriceChanging(value);
                    this.SendPropertyChanging();
                    this._UnitPrice = value;
                    this.SendPropertyChanged("UnitPrice");
                    this.OnUnitPriceChanged();
                }
            }
        }

        [Column(Storage = "_UnitsInStock", DbType = "SmallInt")]
        public System.Nullable<short> UnitsInStock
        {
            get
            {
                return this._UnitsInStock;
            }
            set
            {
                if ((this._UnitsInStock != value))
                {
                    this.OnUnitsInStockChanging(value);
                    this.SendPropertyChanging();
                    this._UnitsInStock = value;
                    this.SendPropertyChanged("UnitsInStock");
                    this.OnUnitsInStockChanged();
                }
            }
        }

        [Column(Storage = "_UnitsOnOrder", DbType = "SmallInt")]
        public System.Nullable<short> UnitsOnOrder
        {
            get
            {
                return this._UnitsOnOrder;
            }
            set
            {
                if ((this._UnitsOnOrder != value))
                {
                    this.OnUnitsOnOrderChanging(value);
                    this.SendPropertyChanging();
                    this._UnitsOnOrder = value;
                    this.SendPropertyChanged("UnitsOnOrder");
                    this.OnUnitsOnOrderChanged();
                }
            }
        }

        [Column(Storage = "_ReorderLevel", DbType = "SmallInt")]
        public System.Nullable<short> ReorderLevel
        {
            get
            {
                return this._ReorderLevel;
            }
            set
            {
                if ((this._ReorderLevel != value))
                {
                    this.OnReorderLevelChanging(value);
                    this.SendPropertyChanging();
                    this._ReorderLevel = value;
                    this.SendPropertyChanged("ReorderLevel");
                    this.OnReorderLevelChanged();
                }
            }
        }

        [Column(Storage = "_Discontinued", DbType = "Bit NOT NULL")]
        public bool Discontinued
        {
            get
            {
                return this._Discontinued;
            }
            set
            {
                if ((this._Discontinued != value))
                {
                    this.OnDiscontinuedChanging(value);
                    this.SendPropertyChanging();
                    this._Discontinued = value;
                    this.SendPropertyChanged("Discontinued");
                    this.OnDiscontinuedChanged();
                }
            }
        }

        [Association(Name = "Supplier_Product", Storage = "_Supplier", ThisKey = "SupplierID", OtherKey = "SupplierID", IsForeignKey = true)]
        public Supplier Supplier
        {
            get
            {
                return this._Supplier.Entity;
            }
            set
            {
                Supplier previousValue = this._Supplier.Entity;
                if (((previousValue != value)
                            || (this._Supplier.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._Supplier.Entity = null;
                        previousValue.Products = null;
                    }
                    this._Supplier.Entity = value;
                    if ((value != null))
                    {
                        value.Products = this;
                        this._SupplierID = value.SupplierID;
                    }
                    else
                    {
                        this._SupplierID = default(int);
                    }
                    this.SendPropertyChanged("Supplier");
                }
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

 可以发现,EntitySet这样集概念的属性变成了EntityRef单体的引用属性