This is a migrated thread and some comments may be shown as answers.

Simple instructions for incorporating a model into an existing website (not project)

3 Answers 84 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Robert
Top achievements
Rank 1
Robert asked on 04 Dec 2012, 09:27 PM
I am hoping someone can help me.  I have only really created websites using the traditional website method (not a project).  I created a model, but I don't think I am referencing the model correctly in my website.

This is what I have done.
I right-clicked on my website (in the solution explorer) and selected "Add Reference.."
I browsed to my model (CAFModel) and navigated to the Model ->Bin->Release folder and selected both the
CAFModel.dll and the Telerik.OpenAccess.35.Extensions.dll

On the asp.net webform where I want to use the model, I added:
 
using CAFModel;


This didn't seem to do the trick, however. 

I get the following error when I try the below test code:
Code:
using (EntitiesModel CAFModel = new EntitiesModel())
{
 Member member1 = new Member();
 member1.FirstName = "first name";
CAFModel.Add(member1);
}

Error:
Error 103 'CAFModel.EntitiesModel': type used in a using statement must be implicitly convertible to 'System.IDisposable'
Error 102 'CAFModel.EntitiesModel' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'CAFModel.EntitiesModel' could be found (are you missing a using directive or an assembly reference?) D:\Documents and Settings\Robert\My Documents\My Dropbox\My Web Sites\sbcaf\test\default.aspx.cs 29 22 D:\...\sbcaf\

Any help would be appreciated.

Thanks,

Rob

3 Answers, 1 is accepted

Sort by
0
Hristo Marinov
Telerik team
answered on 06 Dec 2012, 03:51 PM
Hello Robert,

The reason for the exception being thrown in your case is that the reference to Telerik.OpenAccess is missing. In order to use an OpenAccess model (Model Project) from another project (Consumer Project) please follow these steps:

1. In the Consumer Project add reference to:
  • Model Project
  • Telerik.OpenAccess
  • Telerik.OpenAccess.35.Extensions
2. Copy the connection string from the config file of the Model Project into the config file of the Consumer Project

After that in each class you use the model you will need to add an using Telerik.OpenAccess to your namespace imports. This is needed because all the methods of the OpenAccess context are located in that namespace. For more detailed information about consuming an OpenAccess model from another project please have a look here. You can also have a look at this video about 'Creating a Web Application with Telerik OpenAccess ORM Database First Development'.

Let me know if you need additional directions.

Greetings,
Hristo Marinov
the Telerik team
Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
0
Robert
Top achievements
Rank 1
answered on 06 Dec 2012, 05:55 PM
Thanks for replying, Hristo.  I did add the connection string to my Web.Config with no change in the errors I am receiving.

The problem seems to be two fold.
1.  As I understand it, I am not using a visual studio project for my website.  It is a Visual Studio "Website", not a "Web Application".  In your example that you referenced (i.e. consuming an OpenAccess model from another project), these instructions are people that have a web application project, not a basic website (that is not pre-compiled). 

Therefore, as I understand it, I need to add references to the applicable dlls; this is where problem #2 seems to come into play.

2.  When I "Add Reference..." and navigate to my OpenAccess model project (titled CAFModel), and navigate to the Bin folder (release), the only dlls are the CAFModel.dll and the Telerik.OpenAccess.35.Extensions.dll.  There is no Telerik.OpenAccess dll.  Where do I find the Telerik.OpenAccess.dll?

By the way, my code-behind (in the website) does allow me to add a "using Telerik.OpenAccess" import, even without the dll in my bin folder.  Yet, the errors are still there.

Thank you for your help.
-Rob
0
Hristo Marinov
Telerik team
answered on 11 Dec 2012, 11:33 AM
Hi Robert,

Please accept my apologies for the misunderstanding.

The reason why you were not able to find the Telerik.OpenAccess.dll in the Bin folder is that this assembly is installed into the Global Assembly Cache and automatically retrieved from there.

Nevertheless, in a Web Site the principle is the same. To add a reference to a project in the current solution, you should open the Reference Manager window (Add Reference…) and on the left menu navigate to Solution -> Projects. Here you should be able to see all the projects which are included in the current solution. Select the Model Project. After that from the menu navigate to Assemblies -> Extensions. In this dialog you should be able to view all the extension assemblies including the ones provided with Telerik OpenAccess ORM. Here select the Telerik.OpenAccess and Telerik.OpenAccess.35.Extensions assemblies and click OK. After that you should be able to build your solution successfully. This is the method for adding references we recommend instead of directly referring to the files that you can find in the Bin/Release folder.

It will be even easier to setup if you choose the Telerik OpenAccess Web Site project template. This template creates a Web Site and a Telerik OpenAccess Class Library, which contains the model. The only configuration that needs to be done is to copy the connection string from the class library project to the web site and you are done. Here is more detailed information about the Telerik OpenAccess Web Site project template. 

Let me know whether the proposed solution helps.

 
All the best,
Hristo Marinov
the Telerik team
Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
Tags
Getting Started
Asked by
Robert
Top achievements
Rank 1
Answers by
Hristo Marinov
Telerik team
Robert
Top achievements
Rank 1
Share this question
or