Exemple #1
0
        private static List <ServerPushCode> GetServerPushCodes(mystateApiDbEntities1 context, List <PhoneNumberAndSdkWithGcm> phoneNumberAndSdkWithGcm)
        {
            //List<SqlParameter> phoneNumberParameters = new List<SqlParameter>(phoneNumberAndSdkWithGcm.Count);
            List <SqlParameter> sqlParameters = new List <SqlParameter>(phoneNumberAndSdkWithGcm.Count);
            StringBuilder       whereSB       = new StringBuilder();

            for (int index = 0; index < phoneNumberAndSdkWithGcm.Count; index++)
            {
                if (index != 0)
                {
                    whereSB.Append(" or ");
                }
                sqlParameters.Add(new SqlParameter("companyId" + index, phoneNumberAndSdkWithGcm[index].CompanyId));
                sqlParameters.Add(new SqlParameter("phoneNumber" + index, phoneNumberAndSdkWithGcm[index].PhoneNumber));


                whereSB.Append(string.Format("(PhoneNumber = @phoneNumber{0} and CompanyId = @companyId{0})", index));
            }


            string query = @"
                SELECT [PhoneNumber]
                      ,[CompanyId]
                      ,[PushCode]
                      ,[CreatedDate]
                      ,[UpdatedDate]
                      ,[IsInstalled]
                      ,[UninstallationReason]
                  FROM [dbo].[ServerPushCodes]
                  where " + whereSB;

            var sqlQuery = context.Set <ServerPushCode>().SqlQuery(query, sqlParameters.ToArray());

            var result = sqlQuery.ToList();

            return(result);
        }