首先 我们要有对应的数据库 实体对象 也就是类对象
//实体对象类 Model
public class product
{
/// <summary>
/// 商品信息id 主键
/// </summary>
//[DatabaseGenerated(DatabaseGeneratedOption.None)] 去除自增长
[ProductComm]
public long id
{
get;
set;
}
[ProductComm]
public string name
{
get;
set;
}
/// <summary>
/// 创建时间
/// </summary>
public DateTime ctime
{
get;
set;
}
/// <summary>
/// 0正常 1已删除
/// </summary>
public int s
{
get;
set;
}
[NotMapped]
public string username { get; set; }
}
对类对象进行构造 指定表名 主键名称 长度 等等规则 这里不一一列举 需要的同学自己去查
public class ProductMapping : EntityTypeConfiguration<product>
{
public ProductMapping()
{
this.ToTable("product");
this.HasKey(x => x.id);
this.Property(x => x.name).HasMaxLength(50);
//this.HasRequired(x => x.Member).WithMany().HasForeignKey(x => x.MemberId);
}
}
那么到了上面这一步 我们的数据库 已经和Data 类 相互关联起来了 那么我们现在要做的 只是使用它而已
public List<product> GetproductInfo()
{
ConnectionData c = new ConnectionData();
var datas= c.ProductInfo.Where(q => q.id == 1).ToList();
return datas;
}
到了这里 我们已经取出你的实体对象对应的数据库对象了。