先看总体结构

MVC 中aspx的增删改查

LInQ

#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
//     此代码由工具生成。
//     运行时版本:4.0.30319.17929
//
//     对此文件的更改可能会导致不正确的行为,并且如果
//     重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------

namespace MvcApplication3.Models
{
    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;
    
    
    [global::System.Data.Linq.Mapping.DatabaseAttribute(Name="linq")]
    public partial class linqDataContext : System.Data.Linq.DataContext
    {
        
        private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
        
    #region 可扩展性方法定义
    partial void OnCreated();
    partial void InsertNation(Nation instance);
    partial void UpdateNation(Nation instance);
    partial void DeleteNation(Nation instance);
    partial void InsertUsers(Users instance);
    partial void UpdateUsers(Users instance);
    partial void DeleteUsers(Users instance);
    #endregion
        
        public linqDataContext() : 
                base(global::System.Configuration.ConfigurationManager.ConnectionStrings["linqConnectionString"].ConnectionString, mappingSource)
        {
            OnCreated();
        }
        
        public linqDataContext(string connection) : 
                base(connection, mappingSource)
        {
            OnCreated();
        }
        
        public linqDataContext(System.Data.IDbConnection connection) : 
                base(connection, mappingSource)
        {
            OnCreated();
        }
        
        public linqDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) : 
                base(connection, mappingSource)
        {
            OnCreated();
        }
        
        public linqDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) : 
                base(connection, mappingSource)
        {
            OnCreated();
        }
        
        public System.Data.Linq.Table<Nation> Nation
        {
            get
            {
                return this.GetTable<Nation>();
            }
        }
        
        public System.Data.Linq.Table<Users> Users
        {
            get
            {
                return this.GetTable<Users>();
            }
        }
    }
    
    [global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Nation")]
    public partial class Nation : INotifyPropertyChanging, INotifyPropertyChanged
    {
        
        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
        
        private string _NationCode;
        
        private string _NationName;
        
        private EntitySet<Users> _Users;
        
    #region 可扩展性方法定义
    partial void OnLoaded();
    partial void OnValidate(System.Data.Linq.ChangeAction action);
    partial void OnCreated();
    partial void OnNationCodeChanging(string value);
    partial void OnNationCodeChanged();
    partial void OnNationNameChanging(string value);
    partial void OnNationNameChanged();
    #endregion
        
        public Nation()
        {
            this._Users = new EntitySet<Users>(new Action<Users>(this.attach_Users), new Action<Users>(this.detach_Users));
            OnCreated();
        }
        
        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_NationCode", DbType="NVarChar(20) NOT NULL", CanBeNull=false, IsPrimaryKey=true)]
        public string NationCode
        {
            get
            {
                return this._NationCode;
            }
            set
            {
                if ((this._NationCode != value))
                {
                    this.OnNationCodeChanging(value);
                    this.SendPropertyChanging();
                    this._NationCode = value;
                    this.SendPropertyChanged("NationCode");
                    this.OnNationCodeChanged();
                }
            }
        }
        
        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_NationName", DbType="NVarChar(20)")]
        public string NationName
        {
            get
            {
                return this._NationName;
            }
            set
            {
                if ((this._NationName != value))
                {
                    this.OnNationNameChanging(value);
                    this.SendPropertyChanging();
                    this._NationName = value;
                    this.SendPropertyChanged("NationName");
                    this.OnNationNameChanged();
                }
            }
        }
        
        [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Nation_Users", Storage="_Users", ThisKey="NationCode", OtherKey="Nation")]
        public EntitySet<Users> Users
        {
            get
            {
                return this._Users;
            }
            set
            {
                this._Users.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_Users(Users entity)
        {
            this.SendPropertyChanging();
            entity.Nation1 = this;
        }
        
        private void detach_Users(Users entity)
        {
            this.SendPropertyChanging();
            entity.Nation1 = null;
        }
    }
    
    [global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Users")]
    public partial class Users : INotifyPropertyChanging, INotifyPropertyChanged
    {
        
        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
        
        private string _UserName;
        
        private string _Password;
        
        private System.Nullable<bool> _Sex;
        
        private string _NickName;
        
        private System.Nullable<System.DateTime> _Birthday;
        
        private string _Nation;
        
        private EntityRef<Nation> _Nation1;
        
    #region 可扩展性方法定义
    partial void OnLoaded();
    partial void OnValidate(System.Data.Linq.ChangeAction action);
    partial void OnCreated();
    partial void OnUserNameChanging(string value);
    partial void OnUserNameChanged();
    partial void OnPasswordChanging(string value);
    partial void OnPasswordChanged();
    partial void OnSexChanging(System.Nullable<bool> value);
    partial void OnSexChanged();
    partial void OnNickNameChanging(string value);
    partial void OnNickNameChanged();
    partial void OnBirthdayChanging(System.Nullable<System.DateTime> value);
    partial void OnBirthdayChanged();
    partial void OnNationChanging(string value);
    partial void OnNationChanged();
    #endregion
        
        public Users()
        {
            this._Nation1 = default(EntityRef<Nation>);
            OnCreated();
        }
        
        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_UserName", DbType="NVarChar(20) NOT NULL", CanBeNull=false, IsPrimaryKey=true)]
        public string UserName
        {
            get
            {
                return this._UserName;
            }
            set
            {
                if ((this._UserName != value))
                {
                    this.OnUserNameChanging(value);
                    this.SendPropertyChanging();
                    this._UserName = value;
                    this.SendPropertyChanged("UserName");
                    this.OnUserNameChanged();
                }
            }
        }
        
        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Password", DbType="NVarChar(20)")]
        public string Password
        {
            get
            {
                return this._Password;
            }
            set
            {
                if ((this._Password != value))
                {
                    this.OnPasswordChanging(value);
                    this.SendPropertyChanging();
                    this._Password = value;
                    this.SendPropertyChanged("Password");
                    this.OnPasswordChanged();
                }
            }
        }
        
        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Sex", DbType="Bit")]
        public System.Nullable<bool> Sex
        {
            get
            {
                return this._Sex;
            }
            set
            {
                if ((this._Sex != value))
                {
                    this.OnSexChanging(value);
                    this.SendPropertyChanging();
                    this._Sex = value;
                    this.SendPropertyChanged("Sex");
                    this.OnSexChanged();
                }
            }
        }
        
        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_NickName", DbType="NVarChar(20)")]
        public string NickName
        {
            get
            {
                return this._NickName;
            }
            set
            {
                if ((this._NickName != value))
                {
                    this.OnNickNameChanging(value);
                    this.SendPropertyChanging();
                    this._NickName = value;
                    this.SendPropertyChanged("NickName");
                    this.OnNickNameChanged();
                }
            }
        }
        
        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Birthday", DbType="DateTime")]
        public System.Nullable<System.DateTime> Birthday
        {
            get
            {
                return this._Birthday;
            }
            set
            {
                if ((this._Birthday != value))
                {
                    this.OnBirthdayChanging(value);
                    this.SendPropertyChanging();
                    this._Birthday = value;
                    this.SendPropertyChanged("Birthday");
                    this.OnBirthdayChanged();
                }
            }
        }
        
        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Nation", DbType="NVarChar(20)")]
        public string Nation
        {
            get
            {
                return this._Nation;
            }
            set
            {
                if ((this._Nation != value))
                {
                    if (this._Nation1.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnNationChanging(value);
                    this.SendPropertyChanging();
                    this._Nation = value;
                    this.SendPropertyChanged("Nation");
                    this.OnNationChanged();
                }
            }
        }
        
        [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Nation_Users", Storage="_Nation1", ThisKey="Nation", OtherKey="NationCode", IsForeignKey=true)]
        public Nation Nation1
        {
            get
            {
                return this._Nation1.Entity;
            }
            set
            {
                Nation previousValue = this._Nation1.Entity;
                if (((previousValue != value) 
                            || (this._Nation1.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._Nation1.Entity = null;
                        previousValue.Users.Remove(this);
                    }
                    this._Nation1.Entity = value;
                    if ((value != null))
                    {
                        value.Users.Add(this);
                        this._Nation = value.NationCode;
                    }
                    else
                    {
                        this._Nation = default(string);
                    }
                    this.SendPropertyChanged("Nation1");
                }
            }
        }
        
        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));
            }
        }
    }
}
#pragma warning restore 1591
View Code

相关文章:

  • 2022-02-05
  • 2022-01-12
  • 2021-07-04
  • 2021-09-16
  • 2021-12-04
  • 2022-02-10
  • 2022-12-23
  • 2021-11-25
猜你喜欢
  • 2022-02-04
  • 2022-01-20
  • 2021-09-28
  • 2022-01-20
  • 2022-01-23
  • 2021-10-01
  • 2021-11-23
相关资源
相似解决方案