How to access the DB in layout.cshtml

Topics: Customizing Orchard, General
Mar 6, 2013 at 2:25 PM
I am trying to access the Database using Entity Framework through model. I have created the object for the class available in model. Using that model object i have called the method. But it throws "MissingMethodException" exception.

Replication Procedure:
Created a new model in tags module named TagCloud.
Created a method GetTagNames(). In which i have coded to get the list of tags from DB.
Created a obj for tag cloud class in layout.cshtml(themes/thethememachine/views)
For Ex:
TagCloud tags=new TagCloud();
tags.GetTagNames()//this line raise MissingMethodException exception.

I have tried to use the DB in layout.cshtml. But in layout.cshtml Data.Entity namespace is not accessible.

Can you please help me to resolve these issues?
Please let me know if you have any questions.
Mar 6, 2013 at 9:40 PM
Does the code work outside of Orchard, like in a Console application?
Mar 7, 2013 at 7:20 AM
Yes. It works in outside of orchard. I have connected 2 DB in orchard. One is working fine. but 2nd one is not working. Getting the above mentioned exception. I am trying to access the 2nd DB in blogcontroller.cs. In that i am getting following exception.

Could not load type 'Sample.Data.Blogs.BlogsEntities' from assembly 'Sample.Data, Version=, Culture=neutral, PublicKeyToken=null'.

Could you please help me to resolve this issues and let me know can we use more than one DB using Entity framework?
Mar 7, 2013 at 9:53 PM
Edited Mar 7, 2013 at 9:54 PM
I'm not sure what the issue is as I have never tried this before myself, but I do know that it is possible to connect to any number of databases you like from Orchard. Usually the problem is the ambient transaction which you need to suppress (search this forum to see how to suppress that, I can't recall from the top of my head).

However, in 1.7 we will most likely not be using TransactionScope anymore, so my guess would be that you don't need to suppress any ambient transaction anymore either (but I could be wrong here). You could try that right now by getting the latest source from the 1.x branch.