Example #1
0
        /// <summary>
        /// 查询单条记录
        /// </summary>
        /// <param name="ExpWhere">lamda表达式</param>
        /// <param name="SqlOrderBy">取值排序字段,如:Id Asc,CreateTime Desc</param>
        /// <param name="UseReadonlySource">是否实用只读数据源,true-是,false-否</param>
        /// <returns></returns>
        public static T Get(Expression <Func <T, bool> > ExpWhere, string SqlOrderBy, bool UseReadonlySource = true)
        {
            ResolveExpress re = new ResolveExpress();

            re.ResolveExpression(re, ExpWhere);
            string SqlWhere = "1=1" + re.SqlWhere;

            object[] SqlParams = re.SqlParams.ToArray();
            string   SqlText   = SqlGenerator.SQLBUILDER_Get(DB.ORM_TabInfo, SqlWhere, SqlOrderBy);

            Data.DBHelper         db = new Data.DBHelper(DB.ORM_TabInfo.ORMConnectionMark, UseReadonlySource);
            Data.Common.DataTable dt = db.ExecTextDataTable(SqlText, SqlParams);
            if (dt != null && dt.Rows.Count > 0)
            {
                DataRow            dr        = dt.Rows[0];
                DynamicBuilder <T> DyBuilder = DynamicBuilder <T> .CreateBuilder(dr);

                T             Model     = DyBuilder.Build(dr);
                ModelBase <T> TempModel = Model as ModelBase <T>;
                TempModel.ModifiedColumns.Clear();
                return(Model);
            }
            else
            {
                return(new T());
            }
        }
Example #2
0
        /// <summary>
        /// 查询单条记录
        /// </summary>
        /// <param name="EWhere">动态属性,如:exOb.IsDel=0</param>
        /// <param name="UseReadonlySource">是否实用只读数据源,true-是,false-否</param>
        /// <returns></returns>
        public static T Get(ExpandoObject EWhere, bool UseReadonlySource = true)
        {
            List <object> SqlParams = new List <object>();
            string        SqlText   = SqlGenerator.SQLBUILDER_Get(DB.ORM_TabInfo, EWhere, out SqlParams);

            Data.DBHelper         db = new Data.DBHelper(DB.ORM_TabInfo.ORMConnectionMark, UseReadonlySource);
            Data.Common.DataTable dt = db.ExecTextDataTable(SqlText, SqlParams);
            if (dt != null && dt.Rows.Count > 0)
            {
                DataRow            dr        = dt.Rows[0];
                DynamicBuilder <T> DyBuilder = DynamicBuilder <T> .CreateBuilder(dr);

                T             Model     = DyBuilder.Build(dr);
                ModelBase <T> TempModel = Model as ModelBase <T>;
                TempModel.ModifiedColumns.Clear();
                return(Model);
            }
            else
            {
                return(new T());
            }
        }