首先要把 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();