Example #1
0
        /// <summary>
        /// 根据主键获得实体对象(包含所有列值),仅支持单主键id,不存在时返回null
        /// </summary>
        /// <typeparam name="TEntity">实体类型</typeparam>
        /// <param name="p_id">主键</param>
        /// <returns>返回实体对象或null</returns>
        public static TEntity GetByID <TEntity>(object p_id)
            where TEntity : Entity
        {
            var pkName = SqliteConnectionEx.GetMapping(typeof(TEntity)).PK.Name;

            return(_db.ForEach <TEntity>(
                       $"select * from `{typeof(TEntity).Name}` where {pkName}=@id", new { id = p_id })
                   .FirstOrDefault());
        }
Example #2
0
 /// <summary>
 /// 获取表的主键名称
 /// </summary>
 /// <param name="p_type">实体类型</param>
 /// <returns></returns>
 public static string GetPrimaryKey(Type p_type)
 {
     return(SqliteConnectionEx.GetMapping(p_type).PK.Name);
 }