Introduction
 Include해서 가져오는 데이터의 값을 필터해서 필요한 값만 가져올수 있도록 하는  

Source

  1. public IQueryable<Category> SearchByParam(string CategoryName, string ProductName)  
  2.    {  
  3.      // 핵심은 Select를 할 때 DB에서 가져올 항목들을 'select new' 안에 명시하고  
  4.      // ToList()로 메모리상에 올리고 이를 return하는것  
  5.   
  6.   
  7.      // Query2와 같이 let을 이용할 수도 있고  
  8.      // Query1과 같이 이용하지 않을수도 있는데  
  9.      // ((ObjectQuery)Query1).ToTraceString()를 해 보았을때 얻어지는  
  10.      // 쿼리는 100% 동일하다.  
  11.   
  12.      var Query1 = (from C in this.ObjectContext.Categories.Include("Products")  
  13.                   .Where(t => CategoryName == "" || t.CategoryName.Contains(CategoryName))  
  14.                   select new  
  15.                   {  
  16.                     C = C,  
  17.                     P = C.Products.Where(tt => ProductName == "" || tt.ProductName.Contains(ProductName))  
  18.                   }).ToList().Select(t => t.C);  
  19.   
  20.      var Query2 = (from C in this.ObjectContext.Categories.Include("Products")  
  21.             .Where(t => CategoryName == "" || t.CategoryName.Contains(CategoryName))  
  22.                   let Product = C.Products.Where(tt => ProductName == "" || tt.ProductName.Contains(ProductName))  
  23.                   select new  
  24.                   {  
  25.                     C = C,  
  26.                     P = Product  
  27.                   }).ToList().Select(t => t.C);  
  28.   
  29.   
  30.   
  31.   
  32.      //string SQL = ((ObjectQuery)Query1).ToTraceString(); // 이를 사용하기 위해선 ToList()를 하지 말아야함  
  33.   
  34.      return Query1.AsQueryable();  
  35.    }  
  36.  }  
  37.   
  38. EXTAREA><br /><br /></P>  

 

 

 

Posted by 백운성
,

Introduction
 같은 파라미터로 [값]/[true/false]를 주어서 어느 타입이던 공통으로 사용 할수 있는 컨버터

Source

  1. /// <summary>  
  2.   /// <summary>  
  3. /// 작성자 : 백운성  
  4. /// 파라미터로 0/true 와 같이 주게되면 value가 0일때 true가 리턴된다.  
  5. ///   
  6. /// XAML  
  7. /// IsChecked="{Binding 답변수, Converter={StaticResource SamevalueToBool}, ConverterParameter='0/true'}"  
  8. /// </summary>  
  9.   
  10. public class SamevalueToBoolConverter : IValueConverter  
  11. {  
  12.   
  13.   public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)  
  14.   {  
  15.     string[] Param = parameter.ToString().Split('/');  
  16.   
  17.     if (!(Param[1].ToLower() == "true" || Param[1].ToLower() == "false"))  
  18.       throw new Exception("true 와 false 이외의 값은 올 수 없습니다");  
  19.   
  20.     bool TrueResult = (Param[1].ToLower() == "true") ? true : false;  
  21.   
  22.   
  23.     if (value != null && value.ToString() == Param[0])  
  24.       return TrueResult;  
  25.     else  
  26.       return (TrueResult == true) ? falsetrue;  
  27.   }  
  28.   
  29.   public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)  
  30.   {  
  31.     throw new NotImplementedException();  
  32.   }  
  33. }  


'SilverLight > Converter' 카테고리의 다른 글

SameValueToVisibleConverter  (0) 2013.09.13
Posted by 백운성
,

Introduction
 같은 파라미터로 [값]/[Visible/Collapsed]를 주어서 어느 타입이던 공통으로 사용 할수 있는 컨버터

Source

  1. /// <summary>  
  2. /// 작성자 : 백운성  
  3. /// 파라미터로 0/Visible과 같이 주게되면 value가 0일때 Visible이 된다.  
  4. ///   
  5. /// XAML  
  6. /// Visibility="{Binding 답변수, Converter={StaticResource SameValueToVisible}, ConverterParameter='0/Collapsed'}"  
  7. /// </summary>  
  8. public class SameValueToVisibleConverter : IValueConverter  
  9. {  
  10.   
  11.   public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)  
  12.   {  
  13.     string[] Param = parameter.ToString().Split('/');  
  14.   
  15.     if (!(Param[1] == "Visible" || Param[1] == "Collapsed"))  
  16.       throw new Exception("Visible 과 Collapsed 이외의 값은 올 수 없습니다");  
  17.   
  18.     Visibility TrueResult = (Param[1] == "Visible") ? Visibility.Visible : Visibility.Collapsed;  
  19.   
  20.   
  21.     if (value != null && value.ToString() == Param[0])  
  22.       return TrueResult;  
  23.     else  
  24.       return (TrueResult == Visibility.Visible) ? Visibility.Collapsed : Visibility.Visible;  
  25.   }  
  26.   
  27.   public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)  
  28.   {  
  29.     throw new NotImplementedException();  
  30.   }  
  31. }  


'SilverLight > Converter' 카테고리의 다른 글

SamevalueToBoolConverter  (0) 2013.09.13
Posted by 백운성
,