0

I want to copy a premaded database in user's device. then use it in the android App. but I don't know where is the best place for that. (a place that I can copy file to it)

for example: I have a database named "FoodsDB.db" in assets folder When application starts for first time, it copies the DB from assets to user's Device Then in DatabaseHelper address it and use it

Hossain Khademian
  • 1,616
  • 3
  • 19
  • 29

2 Answers2

0

Right off the bat without knowing exactly your code I'd try and guess that when you say "I don't want to submit changes" means you shouldn't invoke SaveChanges(). Shouldn't you try to completely discard the entities, then? I doubt it's that simple, but I post this nonetheless.

pid
  • 11,472
  • 6
  • 34
  • 63
  • how can do i completely discard changes of one [Entity]? – Hossain Khademian Jan 23 '14 at 20:44
  • Don't invoke SaveChanges(). You should use a using() {} statement because the entity context is IDisposable. When you don't invoke SaveChanges() and the using exits, the context will be disposed and any unsaved changes won't be persisted. – pid Jan 23 '14 at 20:50
  • But Still Some Add/Update/Valid Deletes Are Available. I add an short/simple example to Q. – Hossain Khademian Jan 23 '14 at 20:56
  • @pid If I understand correctly, he is doing something like adding 3 entries, and now he wants to remove just one of the entries and save the other two. if he disposes without saving changes than the other two new entries will not be saved. – Kyle Jan 23 '14 at 22:19
  • Yes, that's why this first attempt won't work. He later added the full example code and this fact became evident. – pid Jan 23 '14 at 22:32
0

After you've added the example code I can see it's different then I thought. You won't be able to use a rollback (see unit of work pattern). What you need here is a PARTIAL undo, which is different then the full-scale undo I initially proposed by throwing away the entire context.

Look here for an excellent solution to your problem:

Entity Framework .Remove() vs. .DeleteObject()

Community
  • 1
  • 1
pid
  • 11,472
  • 6
  • 34
  • 63
  • Thanks. But I use ADO.NET Entity Model Framework (With AutoGenerated Use). And Entities Class is DB. I can't find DeleteObject in 1-DB 2-DB.Products – Hossain Khademian Jan 23 '14 at 21:12
  • Maybe a good advice would be to re-organize the code so that you never add that entity that you later remove. Can't you add an if statement where you delete the entity and negate it? Like so: if(!deleteCondition) { add_entity } else { /* do nothing */ } – pid Jan 23 '14 at 21:25