这个是插入实体方法: TempLicense te = new TempLicense(); te.ID = Guid.NewGuid().ToString(); te.KeyWord =”12”; comm.AddNewEntityString(te);
更新就是 /// /// 更新实体表 /// /// /// public bool UpdateEntity(object obj) where T : class,new() { bool flag = false; try {
using (IDbConnection conn = OpenConnection()) { conn.Update<T>((T)obj); } } catch (Exception ex) { flag = false; } return flag;一样的自动适配主键,另外关于实体映射问题,需要
实体与表要一一对应 如果要加新属性就需要在实体类中 加 /// /// TempLicense:实体对象映射关系 /// [Serializable] public class UsersEntityORMMapper : ClassMapper {
public UsersEntityORMMapper() { base.Table("TempLicense"); Map(f => f.New_id).Ignore();//设置忽略 //Map(f => f.Name).Key(KeyType.Identity);//设置主键 (如果主键名称不包含字母“ID”,请设置) AutoMap(); } }