zoukankan      html  css  js  c++  java
  • c#EntityFrameworkcodeFirst模式

    一、首先定义数据类

    [DataContract(Namespace="http://www.cninnovation.com/Services/2012")]
      public class RoomReservation : INotifyPropertyChanged
      {
        private int id;
        [DataMember]
        public int Id
        {
          get { return id; }
          set { SetProperty(ref id, value); }
        }

        private string roomName;
        [DataMember]
        [StringLength(30)]
        public string RoomName
        {
          get { return roomName; }
          set { SetProperty(ref roomName, value); }
        }

        private DateTime startTime;
        [DataMember]
        public DateTime StartTime
        {
          get { return startTime; }
          set { SetProperty(ref startTime, value); }
        }

        private DateTime endTime;
        [DataMember]
        public DateTime EndTime
        {
          get { return endTime; }
          set { SetProperty(ref endTime, value); }
        }

        private string contact;
        [DataMember]
        [StringLength(30)]
        public string Contact
        {
          get { return contact; }
          set { SetProperty(ref contact, value); }
        }

        private string text;
        [DataMember]
        [StringLength(50)]
        public string Text
        {
          get { return text; }
          set { SetProperty(ref text, value); }
        }
       

        protected virtual void OnNotifyPropertyChanged(string propertyName)
        {
          PropertyChangedEventHandler eventHandler = PropertyChanged;
          if (eventHandler != null)
          {
            eventHandler(this, new PropertyChangedEventArgs(propertyName));
          }
        }

        protected virtual void SetProperty<T>(ref T item, T value, [CallerMemberName] string propertyName = null)
        {
          if (!EqualityComparer<T>.Default.Equals(item, value))
          {
            item = value;
            OnNotifyPropertyChanged(propertyName);
          }
        }

        public event PropertyChangedEventHandler PropertyChanged;
      }

    二、定义继承DbContext类

      public class RoomReservationContext : DbContext
      {

        public RoomReservationContext()
          : base("name=RoomReservation")
        {

        }
        public DbSet<RoomReservation> RoomReservations { get; set; }
      }

    三、编译项目

    编译后会生成对应dbf数据库文件

    怎么通过visualstudio打开呢?

    1.

    2.天假连接数据库

    3.添加成功后

    数据库物理位置C:UsersAdministratorRoomReservation.mdf

  • 相关阅读:
    性能测试——监控前端性能
    centos7 查看防火墙状态
    Flutter项目实战之女装商城------火爆专区实现、商品分类数据准备
    鸿蒙系统,我要拥抱你~~
    【python3】python中 r'', b'', u'', f'' 的含义
    【python3】excel输入输出
    【python3】return和yield的区别
    【python3】spyder中清除变量命令
    【文章知识点】深度解析长末端重复反转录转座子(LTR-RTs)
    【python3】给List添加元素
  • 原文地址:https://www.cnblogs.com/tianmochou/p/8335946.html
Copyright © 2011-2022 走看看