コード例 #1
0
        public void SqlParameterEqualityTest()
        {
            SqlParameter param1 = new SqlParameter("name", null);
            SqlParameter param2 = new SqlParameter("name", null);

            SqlParameter param3 = new SqlParameter("name", "value");
            SqlParameter param4 = new SqlParameter("name", new string(new[] { 'v', 'a', 'l', 'u', 'e' }));

            Assert.IsTrue(param1.Equals(param2));
            Assert.IsTrue(param2.Equals(param1));

            Assert.IsFalse(param1.Equals(param3));
            Assert.IsFalse(param3.Equals(param1));

            Assert.IsTrue(param3.Equals(param4));
            Assert.IsTrue(param4.Equals(param3));
        }
コード例 #2
0
        public string DbType()
        {
            var dbType = new SqlParameter("x", (SqlDbType)Enum.Parse(typeof(SqlDbType), _dataType, true)).DbType.ToString();

            if (dbType.Equals("String", StringComparison.CurrentCultureIgnoreCase))
            {
                dbType = "AnsiString";
            }

            return(dbType);
        }
コード例 #3
0
        public UserAddress CreateOrUpdate(UserAddress address)
        {
            try
            {
                var returnVal = new SqlParameter("@RID", SqlDbType.Int)
                {
                    Direction = ParameterDirection.Output
                };


                var action = new SqlParameter("@Action", address.Id == 0?"INSERT":"UPDATE");
                var id     = new SqlParameter("@Id", address.Id);

                var userId   = new SqlParameter("@UserId", address.UserId);
                var addLine1 = new SqlParameter("@AddLine1", address.AddressLine1);
                var addLine2 = new SqlParameter("@AddLine2", address.AddressLine2);
                var city     = new SqlParameter("@City", address.City);
                var state    = new SqlParameter("@State", address.State);
                var zipCode  = new SqlParameter("@ZipCode", address.ZipCode);
                var country  = new SqlParameter("@Country", address.Country);



                _innovoAssignmentContext.Database.ExecuteSqlRaw(SqlConstants.ADDRESS_CREATE_UPDATE_SP,
                                                                action, id, userId, addLine1, addLine2, city, state, zipCode, country, returnVal);
                int count = (int)returnVal.Value;
                if (action.Equals("INSERT"))
                {
                    address.Id = count;
                }
                else
                {
                    //count > 0 ? true : false;
                }



                return(address);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
        public UserPreferences CreateOrUpdate(UserPreferences pref)
        {
            try
            {
                var returnVal = new SqlParameter("@RID", SqlDbType.Int)
                {
                    Direction = ParameterDirection.Output
                };


                var action = new SqlParameter("@Action", pref.Id == 0 ? "INSERT" : "UPDATE");
                var id     = new SqlParameter("@Id", pref.Id);

                var userId = new SqlParameter("@UserId", pref.UserId);
                var enable = new SqlParameter("@Enable", pref.EnablePromotionNotifications);



                _innovoAssignmentContext.Database.ExecuteSqlRaw(SqlConstants.PREF_CREATE_UPDATE_SP,
                                                                action, id, userId, enable, returnVal);
                int count = (int)returnVal.Value;
                if (action.Equals("INSERT"))
                {
                    pref.Id = count;
                }
                else
                {
                    //count > 0 ? true : false;
                }



                return(pref);
            }
            catch (Exception e)
            {
                return(null);
            }
        }