Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string.Compare(string1, string2, CultureInfo.GetCultureInfo("pt-BR"),
- CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase) == 0
- public class CollationInitializer : CreateDatabaseIfNotExists<MeuContexto>
- {
- public override void InitializeDatabase(MeuContextocontext)
- {
- if(!context.Database.Exists())
- {
- using (SqlConnection connection = new SqlConnection("DefaultConnection"))
- {
- connection.Open();
- using(SqlCommand command = new SqlCommand(string.Format("CREATE DATABASE {0} COLLATE Latin1_General_CI_AI", "MinhaBaseDeDados"), connection))
- {
- command.ExecuteNonQuery();
- }
- }
- SqlConnection.ClearAllPools();
- }
- base.InitializeDatabase(context);
- }
- }
- public class MeuContexto: DbContext
- {
- public MeuContexto() : base("DefaultConnection", throwIfV1Schema: false)
- {
- Database.SetInitializer(new CollationInitializer<MeuContexto>());
- if(!Database.Exists())
- {
- Database.Initialize(true);
- }
- }
- }
- public class CreateDatabaseCollationInterceptor : IDbCommandInterceptor
- {
- private readonly string _collation;
- public CreateDatabaseCollationInterceptor(string collation)
- {
- _collation = collation;
- }
- public void NonQueryExecuted(DbCommand command, DbCommandInterceptionContext<int> interceptionContext) { }
- public void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
- {
- // Apenas para SQL Server
- if (Regex.IsMatch(command.CommandText, @"^create database [.*]$"))
- {
- command.CommandText += " COLLATE " + _collation;
- }
- }
- public void ReaderExecuted(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext) { }
- public void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext) { }
- public void ScalarExecuted(DbCommand command, DbCommandInterceptionContext<object> interceptionContext) { }
- public void ScalarExecuting(DbCommand command, DbCommandInterceptionContext<object> interceptionContext) { }
- }
- using (controle_estoqueEntities entity = new controle_estoqueEntities())
- {
- return (from a in entity.clientes
- where ( (a.nome_cliente == nome || a.nome_cliente.Contains(nome)))
- orderby a.nome_cliente
- select new ClienteDTO
- {IdCliente = a.idcliente,
- NomeCliente = a.nome_cliente}).toList();
Add Comment
Please, Sign In to add comment