mysql 不能用dbcontext_使用DbContext实体类访问数据库

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

///

/// FileInfo:实体类名要和数据表名的名称一样。

///

[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;

///

///

///

public int ID

{

set{ _id=value;}

get{return _id;}

}

///

///

///

public string FileUlr

{

set{ _fileulr=value;}

get{return _fileulr;}

}

///

///

///

public DateTime UploadTime

{

set{ _uploadtime=value;}

get{return _uploadtime;}

}

///

///

///

public int InfoType

{

set{ _infotype=value;}

get{return _infotype;}

}

///

///

///

public int UserID

{

set{ _userid=value;}

get{return _userid;}

}

#endregion Model

}

public class t_FileInfoDB : DbContext

{

public t_FileInfoDB()

: base("ApplicationServices")

{

}

public DbSet FileInfo { get; set; }

}

ApplicationServices是配置节点里边的name

connectionString="Data Source=.\SQL2005;Initial Catalog=CrmSystemDB;Integrated Security=True"

providerName="System.Data.SqlClient" />

使用:

t_FileInfoDB db = new t_FileInfoDB();

var tb = from d in db.FileInfo where d.ID >=0 select d;

return tb.ToList();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值