11

I like working with the entity framework for many reasons- the ease of use of the entity designer, the power of linq, and the ease of binding. Occasionally I want to build a simple app that doesnt need to use a database, but still needs to work with data and display it on screen, in grids etc, so I'd like to just create a quick EF model and use it for this, but it doesnt seem to work very will with just using it for local data.

My question is- is there a correct usage of the EF for working with local data, and perhaps then just serialize/deserialize the whole context to a file? Or is this just too much effort to make work properyly? I used to use Datasets in this way, along with Linq to Dataset, and it works well... So perhaps those are still the better way to go for this scenario?

Brady Moritz
  • 8,624
  • 8
  • 66
  • 100
  • Did you considered using some embedded database? Like i.e. Firebird Embedded that has support for EF? That would IMO much easier. – cincura.net Jun 03 '12 at 05:03

2 Answers2

2

Yes you can use entity framework as local, and also access the data that is currently in-memory, read details as link below:

http://msdn.microsoft.com/en-us/data/jj592872.aspx

Shahram fr
  • 122
  • 1
  • 11
1

I don't know what you mean by "local data" exactly (sounds like it's not a database), but I think the Datasets vs. EF portion of your post is (for me) the real question.

EF is great when you need to model robust business logic, are implementing a Domain Model pattern, using Domain Driven Design, etc: basically any scenario where a Table Module or Active Record pattern is inappropriate.

When you just need to display some grids of data, and the business logic is very simple, Datasets are definitely the way to go (in my experience).

ssis_ssiSucks
  • 1,476
  • 1
  • 12
  • 11
  • Yes I should clarify - work with data without a database, ie all in-memory. Basically I'd like to do what I did before in datasets, but use the EF code so it's more compatible if/when I do want to connect it with a DB later. – Brady Moritz Jun 02 '12 at 18:53
  • 1
    You can create an entity model using the designer, or code first, without a database existing; also, EF is "in-memory" in the same sense that a Dataset is. If your real question is "How do I use EF with a datastore other than a database (e.g. XML)?" then take a look at this SO post: http://stackoverflow.com/questions/608477/entity-framework-with-xml-files – ssis_ssiSucks Jun 02 '12 at 19:18
  • I create entities using the designer, but when I try to create a context, it fails with no database connection. perhaps there is anotehr way to use them though? – Brady Moritz Jun 02 '12 at 19:42
  • I just created a forms project, added an Entity Model, created an Entity using the designer, and instantiated the ModelContainer class without error in the Form_Load event handler. What is the error you're getting? – ssis_ssiSucks Jun 02 '12 at 21:29
  • hmm that is what I'm doing, but it throws an exception when it can't find a database connection... I'll have to look further into this. You are using EF 4.x? – Brady Moritz Jun 05 '12 at 15:32