https://github.com/mjebrahimi/sqlinmemory
SqlInMemory is a library for creating SqlServer database on Memory instead of hard disk, at last Drops and Disposes database when you're done with it. This is useful for Integration Testing.
https://github.com/mjebrahimi/sqlinmemory
inmemory inmemory-db inmemory-test integration-testing sqlserver unit-test unit-testing
Last synced: 3 months ago
JSON representation
SqlInMemory is a library for creating SqlServer database on Memory instead of hard disk, at last Drops and Disposes database when you're done with it. This is useful for Integration Testing.
- Host: GitHub
- URL: https://github.com/mjebrahimi/sqlinmemory
- Owner: mjebrahimi
- License: mit
- Created: 2020-03-06T21:20:06.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-02T01:57:21.000Z (over 2 years ago)
- Last Synced: 2025-03-17T16:06:41.972Z (3 months ago)
- Topics: inmemory, inmemory-db, inmemory-test, integration-testing, sqlserver, unit-test, unit-testing
- Language: C#
- Homepage:
- Size: 75.2 KB
- Stars: 33
- Watchers: 4
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.nuget.org/packages/SqlInMemory/)
[](https://opensource.org/licenses/MIT)
[](https://github.com/mjebrahimi/SqlInMemory)# SqlInMemory
**SqlInMemory** is a library for creating SqlServer database on **Memory** instead of hard disk, at last **Drops and Disposes** database when you're done with it. This is useful for **Integration Testing**.
**Note : This library uses [RamDisk](https://github.com/mjebrahimi/RamDisk) which also uses [ImDisk](http://www.ltr-data.se/opencode.html/#ImDisk) in the backend for creating virtual disk drive. Therefore you have to install imdisk first. ([Download link of current stable version 2.0.10](http://www.ltr-data.se/files/imdiskinst.exe))**
## Get Started
### 1. Install Package
```
PM> Install-Package SqlInMemory
```### 2. Use it
Pass your connection string and it will create (mount) a virtual disk drive 'Z' and create database there finaly when disposed, drop database and unmount drive.
```csharp
var connectionString = "Data Source=.;Initial Catalog=TestDb;Integrated Security=true";
using (SqlInMemoryDb.Create(connectionString))
{
//Use database using ADO.NET or ORM//For example using EF Core
services.AddDbContext(opt => opt.UseSqlServer(connectionString));
var serviceProvider = services.BuildServiceProvider();
var appDbContext = serviceProvider.GetService();
appDbContext.Database.Migrate();
//...
}
```## Contributing
Create an [issue](https://github.com/mjebrahimi/SqlInMemory/issues/new) if you find a BUG or have a Suggestion or Question. If you want to develop this project, Fork on GitHub and Develop it and send Pull Request.
A **HUGE THANKS** for your help.
## License
SqlInMemory is Copyright © 2020 [Mohammd Javad Ebrahimi](https://github.com/mjebrahimi) under the [MIT License](https://github.com/mjebrahimi/SqlInMemory/LICENSE).