Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, so i found a solution to this.. its not the best of the coded but its working now.</p> <p>What i had to do was </p> <ol> <li>Create a new WCF Services Layer in my project.</li> <li>Move the "Create&amp;Update" database work to a service class.</li> <li>In the business logic layer, consume the service.</li> <li>If the service.DoWork() method fails, try again (as i said before, it works the second time)</li> </ol> <p>Here is the code in BLL consumig the service</p> <pre><code>using BusinessLogicLayer.WcfServicesLayer.AppStart.Databases; namespace BusinessLogicLayer.AppStart { /// &lt;summary&gt; /// Inicialização e Update de versão dos bancos de dados do sistema /// &lt;/summary&gt; public static class Databases { public static void Start() { //Iniciar DBCore var client = new DatabasesClient(); bool databaseStarted = client.DoWork(); if(!databaseStarted) { var retry = new DatabasesClient(); databaseStarted = retry.DoWork(); } } } } </code></pre> <p>Here is the service class.</p> <pre><code>using System; using System.Data.Entity; using System.Data.Entity.Migrations; namespace WcfServicesLayer.AppStart { // Serviço de inicialização dos bancos de dados da aplicação public class Databases : IDatabases { public bool DoWork() { return StartDatabases(); } private bool StartDatabases() { //Iniciar DBCore return DataBaseStart&lt;DataAccessLayer.DataContexts.Core.Context, DataAccessLayer.Migrations.Core.Configuration&gt;(); } private bool DataBaseStart&lt;T, TC&gt;() where T : DbContext, new() where TC : DbMigrationsConfiguration&lt;T&gt;, new() { //Atualiza a base de dados com base na configuração do migrations try { var migratorConfig = new TC(); var dbMigrator = new DbMigrator(migratorConfig); dbMigrator.Configuration.AutomaticMigrationDataLossAllowed = false; dbMigrator.Update(); return true; } catch (Exception) { //Exceção quando cria o banco a primeira vez? return false; } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload