zoukankan      html  css  js  c++  java
  • odata.EF一些常用配置

    Enable-Migrations //在数据库里建一个表
    Add-Migration //添加
    Update-Database //更新数据
    install-package entityframework //添加最新版的EF
    Install-Package Microsoft.AspNet.Odata //添加最新版的Odata
    Install-Package Jquery //添加最新版的Jquery
    
    
    在EF类里面添加主外键
    
            [Table("Users")] //创建一个表,表名为Users
            public class SUsers
            {
                [Key] //唯一
                public int Ids { get; set; }
    
                [Required] //非空
                public string Uname { get; set; }
                public string Password { get; set; }
                public string Nname { get; set; }
                public string Sex { get; set; }
                public int NationCode { get; set; }
                public DateTimeOffset Birthday { get; set; } //DateTimeOffset就是DateTime类型
    
                [ForeignKey("NationCode")] //定义一个外键,外键为NationCode
                public virtual Nation Nation { get; set; } //外键
            }
            public class Nation
            {
                [Key] //唯一
                public int Ids { get; set; }
                public string NationName { get; set; }
                public virtual ICollection<SUsers> SUsers { get; set; }  //主键
    
            }
        }
    //配置Web.config
      <connectionStrings>
        <add name="UsersContext" connectionString="Data Source=.;Initial Catalog=User;Persist Security Info=True;User ID=sa;Password=123;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
      </connectionStrings>
     //配置Odata
      config.Count().Select().OrderBy().Filter().Expand().MaxTop(null);
                ODataModelBuilder builder = new ODataConventionModelBuilder();
                builder.EntitySet<Users>("Users");
                config.MapODataServiceRoute(
                    routeName: "odata",
                    routePrefix: "odata",
                    model: builder.GetEdmModel());
    

      

  • 相关阅读:
    Redis Info详解
    ABAP常用事务码
    ABAP区别CLEAR、REFRESH、FREE
    virtualbox安装增强功能时【未能加载虚拟光盘】
    https://www.safaribooksonline.com/home/
    图文教程教您蓝底照片更换成白底和红底的方法
    URAL1495. One-two, One-two 2(dp)
    URAL1513. Lemon Tale(dp)
    URAL1900 Brainwashing Device(dp)
    Codeforces Round #228 (Div. 1)B
  • 原文地址:https://www.cnblogs.com/zJuevers/p/9173135.html
Copyright © 2011-2022 走看看