Exemplo n.º 1
0
        public IQueryBuilder QueryIds <T>(List <T> rs) where T : IDataObject
        {
            if (!rs.Any())
            {
                return(Qb.Fmt("SELECT 1 as Id, 'no-rid' as RID WHERE FALSE"));
            }
            var t   = rs.First().GetType();
            var id  = FiTechBDadosExtensions.IdColumnOf[t];
            var rid = FiTechBDadosExtensions.RidColumnOf[t];

            var retv = Qb.Fmt($"SELECT {id}, {rid} FROM {t.Name} WHERE") + Qb.In(rid, rs, i => i.RID);

            //if(rs.Any(i=> i.Id>0)) {
            //    var existingIds = rs.Where(i => i.Id > 0).ToList();
            //    if (existingIds.Count > 0) {
            //        retv += Qb.Or() + Qb.In(id, existingIds, i => i.Id);
            //    }
            //}
            return(retv);
        }
Exemplo n.º 2
0
        public IQueryBuilder QueryIds <T>(List <T> rs) where T : IDataObject
        {
            var type    = rs.FirstOrDefault()?.GetType() ?? typeof(T);
            var id      = FiTechBDadosExtensions.IdColumnOf[type];
            var rid     = FiTechBDadosExtensions.RidColumnOf[type];
            var ridType = ReflectionTool.GetTypeOf(ReflectionTool.FieldsAndPropertiesOf(type).FirstOrDefault(x => x.GetCustomAttribute <ReliableIdAttribute>() != null));

            return(Qb.Fmt($"SELECT {id} AS Id, {rid} AS RID FROM {type.Name} WHERE") + Qb.In(rid, rs, i => Convert.ChangeType(i.RID, ridType)));
        }
Exemplo n.º 3
0
        public IQueryBuilder QueryIds <T>(List <T> rs) where T : IDataObject
        {
            var id  = ReflectionTool.FieldsAndPropertiesOf(typeof(T)).FirstOrDefault(f => f.GetCustomAttribute <PrimaryKeyAttribute>() != null);
            var rid = ReflectionTool.FieldsAndPropertiesOf(typeof(T)).FirstOrDefault(f => f.GetCustomAttribute <ReliableIdAttribute>() != null);

            return(Qb.Fmt($"SELECT {id.Name}, {rid.Name} FROM {typeof(T).Name} WHERE") + Qb.In(rid.Name, rs, i => i.RID));
        }