zoukankan      html  css  js  c++  java
  • 使用DbContext实体类访问数据库

    首先要把 EFCodeFirst类库工程里,添加EntityFramework的引用。

    /// <summary>
    /// FileInfo:实体类名要和数据表名的名称一样。
    /// </summary>
    [Serializable]
    public partial class t_FileInfo
    {
    public t_FileInfo()
    {}
    #region Model
    private int _id;
    private string _fileulr;
    private DateTime _uploadtime;
    private int _infotype;
    private int _userid;
    /// <summary>
    ///
    /// </summary>
    public int ID
    {
    set{ _id=value;}
    get{return _id;}
    }
    /// <summary>
    ///
    /// </summary>
    public string FileUlr
    {
    set{ _fileulr=value;}
    get{return _fileulr;}
    }
    /// <summary>
    ///
    /// </summary>
    public DateTime UploadTime
    {
    set{ _uploadtime=value;}
    get{return _uploadtime;}
    }
    /// <summary>
    ///
    /// </summary>
    public int InfoType
    {
    set{ _infotype=value;}
    get{return _infotype;}
    }
    /// <summary>
    ///
    /// </summary>
    public int UserID
    {
    set{ _userid=value;}
    get{return _userid;}
    }
    #endregion Model

    }

    public class t_FileInfoDB : DbContext
    {
    public t_FileInfoDB()
    : base("ApplicationServices")
    {

    }
    public DbSet<t_FileInfo> FileInfo { get; set; }

    }

    ApplicationServices是配置节点里边的name

    <connectionStrings>
    <add name="ApplicationServices"
    connectionString="Data Source=.\SQL2005;Initial Catalog=CrmSystemDB;Integrated Security=True"
    providerName="System.Data.SqlClient" />
    </connectionStrings>

    使用:

    t_FileInfoDB db = new t_FileInfoDB();

    var tb = from d in db.FileInfo where d.ID >=0 select d;
    return tb.ToList();

  • 相关阅读:
    Codeforces Round #443 (Div. 2)ABC
    Codeforces Round #442 (Div. 2) ABC
    Wannafly挑战赛2 Cut
    热爱工作的蒜蒜
    Codeforces Round #441 (Div. 2) (ABC)
    Codeforces Round #440 (Div. 2)(ABC)
    Codeforces Round #439 (Div. 2)(ABC)
    sphinx 分词搭建手册
    [转]Chrome 控制台console的用法
    shell脚本复制文件夹内容到另外的文件夹,如果存在则自动备份
  • 原文地址:https://www.cnblogs.com/lucoo/p/3039733.html
Copyright © 2011-2022 走看看