Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am developing an application with ASP.NET MVC using Visual Studio 2017 applying the Code First approach. I have three classes (tables) in the model and I am trying to create a class that simulates the BD.
I'm trying to store data in memory without using db. I don't now how to add new item?
This is my Clas DataBase (repository)

What I have tried:

C#
<pre><pre lang="c#">public class DataBase : IDataBase
{
    private List<Proveedor> proveedors;
    private List<Factura> facturas;
    private List<FacturadeArticulo> facturadeArticulos;

    public  DataBase()
    {
        this.proveedors= new List<Proveedor>();
        this.facturas= new List<Factura>();
        this.facturadeArticulos= new List<FacturadeArticulo>();
    }
    public Proveedor AddProveedor(Proveedor item)
    {
        // acces db
            if (item == null)  
            {  
                throw new ArgumentNullException("item");  
            }  
  
            users.Add(item);  
            return item; 

    }
}


My interface IDataBase

C#
public interface IDatabase
    {
        Proveedor Add(Proveedor item);

    }


Is that possible in this way save data in memory..Tnx
Posted
Updated 8-Nov-18 5:30am
Comments
F-ES Sitecore 8-Nov-18 6:51am    
Yes it's possible. You're adding to a "users" object that doesn't seem to exist though.
Member 13947747 8-Nov-18 7:02am    
But I don't now how to add new item. When I try to add a new item and select a table Proveedor it's empty. My mistake user = proveedors

1 solution

You may try to look at Effort to test your app without a real database. Here's an example: Using an In Memory Database as a Test Double with Entity Framework - Steve Fenton[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900