Guest User

Untitled

a guest
Feb 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. string.Compare(string1, string2, CultureInfo.GetCultureInfo("pt-BR"),
  2. CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase) == 0
  3.  
  4. public class CollationInitializer : CreateDatabaseIfNotExists<MeuContexto>
  5. {
  6. public override void InitializeDatabase(MeuContextocontext)
  7. {
  8. if(!context.Database.Exists())
  9. {
  10. using (SqlConnection connection = new SqlConnection("DefaultConnection"))
  11. {
  12. connection.Open();
  13. using(SqlCommand command = new SqlCommand(string.Format("CREATE DATABASE {0} COLLATE Latin1_General_CI_AI", "MinhaBaseDeDados"), connection))
  14. {
  15. command.ExecuteNonQuery();
  16. }
  17. }
  18.  
  19. SqlConnection.ClearAllPools();
  20. }
  21.  
  22. base.InitializeDatabase(context);
  23. }
  24. }
  25.  
  26. public class MeuContexto: DbContext
  27. {
  28. public MeuContexto() : base("DefaultConnection", throwIfV1Schema: false)
  29. {
  30. Database.SetInitializer(new CollationInitializer<MeuContexto>());
  31. if(!Database.Exists())
  32. {
  33. Database.Initialize(true);
  34. }
  35. }
  36. }
  37.  
  38. public class CreateDatabaseCollationInterceptor : IDbCommandInterceptor
  39. {
  40. private readonly string _collation;
  41.  
  42. public CreateDatabaseCollationInterceptor(string collation)
  43. {
  44. _collation = collation;
  45. }
  46.  
  47. public void NonQueryExecuted(DbCommand command, DbCommandInterceptionContext<int> interceptionContext) { }
  48. public void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
  49. {
  50. // Apenas para SQL Server
  51. if (Regex.IsMatch(command.CommandText, @"^create database [.*]$"))
  52. {
  53. command.CommandText += " COLLATE " + _collation;
  54. }
  55. }
  56.  
  57. public void ReaderExecuted(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext) { }
  58. public void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext) { }
  59. public void ScalarExecuted(DbCommand command, DbCommandInterceptionContext<object> interceptionContext) { }
  60. public void ScalarExecuting(DbCommand command, DbCommandInterceptionContext<object> interceptionContext) { }
  61. }
  62.  
  63. using (controle_estoqueEntities entity = new controle_estoqueEntities())
  64. {
  65. return (from a in entity.clientes
  66. where ( (a.nome_cliente == nome || a.nome_cliente.Contains(nome)))
  67. orderby a.nome_cliente
  68. select new ClienteDTO
  69. {IdCliente = a.idcliente,
  70. NomeCliente = a.nome_cliente}).toList();
Add Comment
Please, Sign In to add comment