如何在不使用数据库的情况下在C#ASP.NET MVC中保存数据? [英] How to save data in C# ASP.NET MVC without using database?

查看:203
本文介绍了如何在不使用数据库的情况下在C#ASP.NET MVC中保存数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2017使用Code First方法开发ASP.NET MVC的应用程序。我在模型中有三个类(表),我正在尝试创建一个模拟BD的类。

我试图在不使用db的情况下将数据存储在内存中。我现在不知道如何添加新项目?

这是我的Clas数据库(存储库)



我试过的:



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:

<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; 

    }
}





我的界面IDataBase





My interface IDataBase

public interface IDatabase
    {
        Proveedor Add(Proveedor item);

    }





这样就可以将数据保存在内存中... .tnx



Is that possible in this way save data in memory..Tnx

推荐答案

您可以尝试查看努力来测试您的应用,而无需真正的数据库这是一个例子:使用内存数据库作为具有实体框架的测试双重 - Steve Fenton [ ^ ]
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[^]


这篇关于如何在不使用数据库的情况下在C#ASP.NET MVC中保存数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆