1

I have following code

 using  (AdventureWorksEntities database = new AdventureWorksEntities())

But it is showing that

'New_WCF_App1.AdventureWorksEntities': type used in a using statement must be implicitly convertible to 'System.IDisposable'

How to solve this

3 Answers 3

6

Such an error when using the using statements for data contexts in WCF most likely means that you are missing the reference to the System.Data.Entity assembly.

Sign up to request clarification or add additional context in comments.

Comments

4

Well, the error message is reasonably clear - AdventureWorksEntities doesn't implement the IDisposable interface. It can't be disposed, so you can't use it as the resource in a using statement.

Next you need to work out whether it should implement IDisposable, or whether it really doesn't have any resources to dispose.

EDIT: According to comments, with Entity Framework 4 this should work without any extra implementation, as the auto-generated code already implements IDiposable.

5 Comments

This is incorrect. The new entity model will auto generate and it will implement IDisposable auto-magically.
@bugnuker: It's correct for the question - if the OP were using the new generator, presumably they wouldn't have had the problem at all, would they? When you say "new" - you did notice that this question and answer were both in February 2011, right?
2011 should have been entity 4, and this was working in 2011. I guess it all depends on Codefirst/Database first and what version the user was using. At anyrate, as of today, with current Framework, add reference to the corrent Entity dll. - I'm not trying to rain on your accepted Answer. I came to this page today due to me needing to find the correct answer for todays technology. If a user is using old entity framrwork, your answer could surely work for someone. Anyone who has updated, will need the updated answer.
@bugnuker: I'll certainly edit - but it strikes me that anyone who has updated won't run into this as a question in the first place. They should already have a reference to the relevant assembly, as otherwise I'd expect a whole heap of other errors.
Ah, yes. If everything is in the same project, your are 100% correct. However, in my case, My entity Model project is separated from the business logic that uses that model. The BLL project needs a reference to the entity project and that entity DLL to work.
2

You need to add a reference to System.Data.entity (like krzysztofkarolczak said) (below 5.0) or EntityFramework.dll (entity 5.0) and this will solve your problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.