django rest framework – How to Lazy load datatable with client sided processing?

I have a table with 3500 entries and foreign keys.

I’m using client-sided processing datatables with: django-rest-framework and Ajax.

It takes up to 10 seconds to load.

Is there a way to show the first 10 entries (first page results) – for the user not to think that my website is broken, because it’s taking too long – while the rest of the entries loads in the background?

Also looking for optimizations for the load speed.
Thank you for your time.

testing – Simulate SqlConnectionException with Simmy and Entity Framework

I’m trying to use Simmy to test service resilience in case of failure. I’ve found Simmy which looks promising but my guess is that is can only be used along with Polly. Since my main point of failure can be the database connection, I would like to inject failure at the Entity Framework part of the code. Is that possible with Simmy? Or is there any other way to inject failure on the Entity Framework side for some chaos engineering?

In Entity Framework, how can I get a conditional sequence value?

I have entities in my application that require a unique human friendly identifier that include a sequence integer unique to a subset. For example, in project management software you might have a project called “SUPPORT” and then cases related to this project are automatically sequentially numbered as “SUPPORT-1”, “SUPPORT-2”, etc.

Q: How can I get a unique identifier that is conditional to other properties on the entity instance?


I have (temporarily) implemented this in my application by overriding the DbContext.SaveChanges() method, check the latest value in the database for cases related to the project and then create a string with the project name and the sequence number. This doesn’t seem robust and I am looking for a proper pattern.

Researching patterns I have found the modelBuilder.HasSequence<int>() method in the EF Core documentation but I don’t see how I can implement this such that is conditional on the value of the project (so a unique sequence for cases in “SUPPORT”, not overlapping with cases in “SOFTWARE” project).

I am currently using Entity Framework Core 3.1.

c# – Entity Framework tentando inserir registro duplicado

Estou iniciando uma aplicação em Blazor, utilizando Entity Framework e banco MySQL.

Abaixo vou detalhar as Tabelas, Models, Contexto e Método que está me apresentando problema:

Tabelas: https://i.stack.imgur.com/d8UMW.png

Contexto:

public class ContextoEtapa : Contexto
{
    public DbSet<Etapa> Etapa { get; set; }
}

Models:

public class Etapa 
{
    public int Id { get; set; }

    public string Descricao { get; set; }

    public bool Ativo { get; set; }

    public bool Finalizadora { get; set; }

    (InverseProperty("EtapaPai"))
    public virtual List<EtapaVinculada> ListaEtapaVinculada { get; set; }
}
(Table("etapa_vinculada"))
public class EtapaVinculada
{
    public int Id { get; set; }

    public string Descricao { get; set; }

    (Column("id_etapa_pai"))
    public int EtapaPaiId { get; set; }

    public virtual Etapa EtapaPai { get; set; }

    (Column("id_etapa_filha"))
    public int EtapaFilhaId { get; set; }

    public virtual Etapa EtapaFilha { get; set; }
}

Código de exemplo que falha (InnerException = {“Duplicate entry ‘2’ for key ‘PRIMARY'”}):

public void Adicionar()
{
    try
    {
        var etapa = new Etapa();
        var etapaVinculada = new EtapaVinculada();

        etapa.ListaEtapaVinculada = new List<EtapaVinculada>();
        etapa.Descricao = "Aprovada";

        using (var contexto = new ContextoEtapa())
        {
            etapaVinculada.EtapaPai = etapa;
            etapaVinculada.EtapaPaiId = etapa.Id;
            etapaVinculada.EtapaFilhaId = 2;
            etapaVinculada.EtapaFilha = contexto.Etapa.Where(x => x.Id == 2).FirstOrDefault();
            etapaVinculada.Descricao = "Retornar para Desenvolvimento";

            etapa.ListaEtapaVinculada.Add(etapaVinculada);
        }

        using (var contexto = new ContextoEtapa())
        {
            contexto.Etapa.Add(etapa);
            contexto.SaveChanges();
        }
    }
    catch (Exception excp)
    {
        throw excp;
    }
}

Obs: São códigos de exemplos que refletem uma situação real da minha aplicação. No meu caso eu preencho o objeto etapa em determinado momento utilizando um escopo de contexto, e depois para salvar no banco utilizo outro escopo de contexto, caindo então no erro de registro Duplicado (InnerException = {“Duplicate entry ‘2’ for key ‘PRIMARY'”}). Ao que me parece o Entity tenta inserir novamente na tabela de etapas o objeto da etapaVinculada de ID 2.

Obs2: Se eu fizer tudo dentro do mesmo escopo de contexto funciona corretamente.

Alguém consegue me dar uma luz ae pra ver onde to errando, por favor.

c# – Entity Framework Key exists

I have a .NET Core application that has a connection to a SQLite database via Entity Framework v5.

The Datastructure (shortened) is like this. The (JsonIgnore) is for de-/serializing JSON and should pose a problem.

public class DBEntry
{
    (JsonIgnore)
    (Key)
    public int Id { get; set; }

    public string Some { get; set; }
    public string Data { get; set; }
}

Now in my class that inherits from DbContext I have an overridden call for SaveChanges() like this:

public override int SaveChanges()
{
    DateTime currentTime = DateTime.Now;

    foreach (var entry in this.ChangeTracker.Entries()
        .Where(e => e.State == EntityState.Added))
    {
        try
        {
            var createdDateEntry = entry.Property("CreatedDate");
            if (createdDateEntry != null)
            {
                entry.Property("CreatedDate").CurrentValue = currentTime;
            }
        }
        catch (Exception)
        { }

        try
        {
            var lastUpdatedEntry = entry.Property("LastUpdatedDate");
            if (lastUpdatedEntry != null)
            {
                entry.Property("LastUpdatedDate").CurrentValue = currentTime;
            }
        }
        catch (Exception)
        { }
    }

    foreach (var entry in this.ChangeTracker.Entries()
        .Where(e => e.State == EntityState.Modified))
    {
        try
        {
            var lastUpdatedEntry = entry.Property("LastUpdatedDate");
            if (lastUpdatedEntry != null)
            {
                entry.Property("LastUpdatedDate").CurrentValue = currentTime;
            }
        }
        catch (Exception)
        { }
    }

    return base.SaveChanges();
}

Both CreatedDate and LastUpdatedDate are DateTime-fields from class DBEntry above.

Now when I fetch an existing item from the Database like this: var existing = _context.MyDatabase.Single(x => x.Some == "SomeString"); and change values and write it to the Database with _context.MyDatabase.Update(existing); and then call _context.SaveChanges();, I get an error message:

Message: 
    System.ArgumentException : An item with the same key has already been added. Key: 1
  Stack Trace: 
    Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
    Dictionary`2.Add(TKey key, TValue value)
    InMemoryTable`1.Create(IUpdateEntry entry)
    InMemoryStore.ExecuteTransaction(IList`1 entries, IDiagnosticsLogger`1 updateLogger)
    InMemoryDatabase.SaveChanges(IList`1 entries)
    StateManager.SaveChanges(IList`1 entriesToSave)
    StateManager.SaveChanges(DbContext _, Boolean acceptAllChangesOnSuccess)
    NonRetryingExecutionStrategy.Execute(TState,TResult)(TState state, Func`3 operation, Func`3 verifySucceeded)
    StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
    DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
    DbContext.SaveChanges()

How can I update an item correctly?

design – Coding framework for very basic functionality

I’m a designer and am currently developing a prototype app where I can see and test my design fast and simple. All I need is variables, very basic functionality like if statements and such. I want to create basic components that has very limited functionality to them.

What is the most basic and simplest framework I can use?

monogame – game engine/library or ui framework?

For a while I have an idea in my head for a game. The game will be my own version of a game dev tycoon game. The game will need a lot of UI components (treeview, textbox, dropdown menu, etc). I looked at unity first but I did not like the UI components there. I also looked at Godot but the mono version is not yet completed and in alpha(i don’t feel comfortable using it while it is in alpha). Then I started looking at monogame. But monogame has no UI components as far as I know. Then I thought maybe I can write the UI components myself. But I lack experience so I started searching how I would do that in monogame. I did not find any source that could help me. After that, I kept thinking about how to solve my problem. Then i thought it was maybe a better idea to use a GUI library instead of a gaming one. But I don’t know if it is a good choice to use a UI library for a game project. Does anyone know if it is a good idea ? or does someone have a better alternative ?

What are the "Third party Extensions" ? Which extensions are considered as Third party extension in Magento Framework?

I have two questions.

  • What are the "Third party Extensions" ?
  • Which extensions are considered as Third party extension in Magento
    Framework ?

Thankyou

entity framework – Is it considered a bad practice to include methods in classes that comprise an EF model?

I am working on a project that uses Entity Framework Core. I have a class which represents an entity on which I’m trying to perform validation. Is it considered a bad practice to include a Validate method to the class itself (note that the Validate method would not be the only method included)? Is it better to create a repository for the class, and implement validation in the repository? Or to create validation classes per entity? I think there is no “best” approach, but in your opinion, where should the Validation method be implemented? Thank you.

sql server – No connection pooling happening with PHP Doctrine Framework

How to enable Connection Pooling with Doctrine PHP framework please ?, all the DB connections from the application are NonPooled and hence causing high PREEMPTIVE_OS wait stats. Any advice on it would be greatly appreciated. Thanks