0

I have a Dbcontext which say for files,

   private FileDB db = new FileDB();

now i have stored files in my DB, when i using in controller(MVC) i just want to have the db context with set of files related to the user not all files, how could i extent the Dbcontext to have that feature.

I dont want to find files belong to that user, inside each action results like

   File file = db.Files.Find(id);

instead i need to have "db" with only files related to that user.

Purushoth
  • 2,673
  • 3
  • 22
  • 36
  • 1
    As a side note: Failing to properly `Dispose` of your `DbContext` will leak connections and can cause your database to become locked for minutes at least. I say this because of the instantiation example you use. Please make sure to always use a `using` statement for your contexts. You can do that by wrapping the instantiation in it, or by having the containing class implement `IDisposable` and then disposing of the context in the `Dispose` method manually. – Travis J Nov 26 '13 at 17:17
  • 1
    Please take a look at this thread http://stackoverflow.com/questions/11197754/entity-framework-one-database-multiple-dbcontexts-is-this-a-bad-idea – Poornima Nov 26 '13 at 17:18
  • Is this what you are asking? http://stackoverflow.com/questions/20210419/how-to-keep-customer-data-segregated/20216234#20216234 or just `db.Files.Where(u => u.Userid = userid)` ? – Colin Nov 26 '13 at 17:37

0 Answers0