L A

L A

  • NA
  • 170
  • 171.1k

Accessing Entity - Error (Entity Framework)

Oct 24 2017 11:31 PM
Hello all,
 
Im working on ASP.Net MVC app, wtih Entity Framework added in a class library. I added refrence of class library project (i.e ADO.Net Entity data model) into my ASP.Net MVC project.
 
 
And in when i try to access Entity in controller's action as shown below
  1. public ActionResult getProductDetails()  
  2. {  
  3. using (SampleTrialEntities entity = new SampleTrialEntities())  
  4. {  
  5. // call entity operation  
  6. }  
  7. return View();  
  8. }  
Here line #3 'using' shows the following error -
 
Error 1 'DataAccessLibrary.SampleTrialEntities': type used in a using statement must be implicitly convertible to 'System.IDisposable'
 
Error 2 The type 'System.Data.Entity.DbContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
 
But when I add ADO.Net Entity data model in ASP.Net MVC project, it works as expected.
So, Should I add ADO.Net Entity data model only in the project in which it is used.? can't I have a separate DAL for this EF and use it in other projects?
 
Can anyone help me, your response is appreciated.

Answers (2)