Josh
Josh

Reputation: 44906

In Memory DataContext

Is it possible to get a LINQ to SQL DataContext to run completely in-memory? Without it touching the database?

I am doing some very rapid prototyping, and want to minimize the surface area for major changes since the UI is changing so fast. However, the data model already exists.

Data access is handled through the use of I[Model]Repository classes that return the actual LINQ to SQL data classes, so I currently have some concrete InMemory[Model]Repository classes that shove stuff in cache. The implementation is a little cumbersome however.

So... is it possible to simply override enough of the DataContext behavior to have it run in-memory and never touch the database. My assumption is that it is not possible, but I thought I would go fishing anyway.

Upvotes: 2

Views: 1552

Answers (1)

DamienG
DamienG

Reputation: 6665

You can only do this if you are prepared to wrap access to the datacontext with your own interface. Then for rapid prototyping you can write your own datacontext alternative that implements this interface and instead uses lists and LINQ to Objects to perform in-memory queries.

Upvotes: 1

Related Questions