Пример #1
0
        public ModelCollection <PropertyContactEntity> ListPropertyContacts(PropertyContactQuery query, bool getCount = false)
        {
            DynamicParameters parameters      = new DynamicParameters();
            DynamicParameters countParameters = new DynamicParameters();

            parameters.Add(query);
            countParameters.AddCountParameters(query);

            // use xml query - if we don't have any xml then just use the normal search - if we do this check here, the proc plan should be better
            string xmlQuery     = query.GetQuery().GetXmlString();
            bool   useQuery     = !string.IsNullOrEmpty(xmlQuery);
            string command      = string.Concat("dbo.SPListPropertyContacts", useQuery ? "Query" : string.Empty);
            string countCommand = string.Concat(command, "_Count");

            if (useQuery)
            {
                parameters.Add("@query", xmlQuery);
            }

            return(Query((connection) =>
            {
                IEnumerable <PropertyContactEntity> data = connection.Query <PropertyContactEntity, AddressEntity, Marker, PropertyContactEntity>(command, (p, a, m) =>
                {
                    p.Address = a ?? new AddressEntity();
                    p.Address.Marker = m;
                    return p;
                }, parameters, commandType: CommandType.StoredProcedure, splitOn: "AddressId,Latitude");

                if (getCount)
                {
                    return new ModelCollection <PropertyContactEntity>(data, connection.Query <int>(countCommand, countParameters, commandType: CommandType.StoredProcedure).FirstOrDefault());
                }

                return new ModelCollection <PropertyContactEntity>(data);
            }));
        }