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

  • 相关阅读:
    主流液晶显示器尺寸参数
    不能访问网络位置的解决方法(转)
    打开Word提示你正试图运行的函数包含有宏或需要宏语言支持的内容
    教你如何防“蹭网”
    ASA数据库瘦身(原创)
    多种解决:“Word无法启动转换器mswrd632.wpc”方法
    百兆线与千兆线网线制作方法
    linux常用命令
    DefaultIfEmpty
    实现手机发送验证码 进行验证
  • 原文地址:https://www.cnblogs.com/tianmochou/p/8335946.html
Copyright © 2011-2022 走看看