Ejemplo n.º 1
0
        public object SelectById(Type type, Object id)
        {
            QueryInfo info = new QueryInfo(type);

            info.CustomSQL = MappingInfo.GetMappingInfo(type).SelectById;
            info.AddParam(GetPrimaryKey(type), id);
            return(Dao.Query(info.ToSQLString(), info.Parameters, type)
                   .SingleOrDefault());
        }
Ejemplo n.º 2
0
        public T SelectById <T>(Object id)
        {
            string sql = MappingInfo.GetMappingInfo <T>().SelectById;

            return(Dao.Query <T>(sql,
                                 new Dictionary <string, object>()
            {
                { GetPrimaryKey(typeof(T)), id }
            }
                                 ).SingleOrDefault());
        }
Ejemplo n.º 3
0
        ///获取xml中配置的 User.Select语句, 或者根据对象的属性映射生成语句
        private string GetMappedOrDefaultSql(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("MappingType", "QueryInfo未指定查询的对象类型!");
            }

            string key = type.Name + ".Select";
            string sql = StatementParser.GetMappedStaticSql(key);

            if (sql.Equals(key))
            {
                sql = (MappingInfo.GetMappingInfo(type).Select + "t");
            }
            return(sql);
        }
Ejemplo n.º 4
0
        public bool Delete <T>(Object id)
        {
            if (id == null)
            {
                return(false);
            }

            Type type = typeof(T);

            MappingInfo info = MappingInfo.GetMappingInfo <T>();

            return(Dao.Execute(
                       info.Delete,
                       new Dictionary <string, object>()
            {
                { GetPrimaryKey(type), id }
            }
                       ) == 1);
        }