• 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

  • 相关阅读:
    VMware虚拟机安装详细教程
    NLP知识点汇总(一)
    自动下载网页上的zip文件并自动解压
    django教程
    redis实现缓存可能带来的问题及总结
    使用github--stanfordnlp--glove训练自己的数据词向量
    mount.nfs: Stale file handle的解决方法
    集智学院 “Deep X:Deep Learning with Deep Knowledge”的公开讲座---总结
    字符串匹配算法总结 (一对一匹配,多模式匹配)
    java sql语句 like%?%报错的问题
  • 原文地址:https://www.cnblogs.com/tianmochou/p/8335946.html
Copyright © 2020-2023  润新知