-1

I created an EntityModel in Visual Studio 2010 to use with Linq. What I see in my Model Browser are:

>AcrrualEntityModel.edmx
>>SteeringWheelModel
>>>Entity Types
>>>>TblFTEReportNew
>>>>>Field1
>>>>>etc..

In my Default.aspx.cs file I should be able to call SteeringWheelModel. This object is generated with the Entity Data Model Wizard. I can see the tables and fields in the model. So, the connection to the database works.

However, in my Default.aspx.cs file I should be able to create a new instance of SteeringWheelModel, so I can use Linq to use tables and fields.

Intellisense does not pick it up. The compiler does not recognize SteeringWheelModel.

What am I missing here? Some "using", some reference?

Thanks in advance!

Roy

1 Answers1

0

You need to import the namespace of EntityModel class by adding a using statement to your code behind. Ex:

using app.data.models

Alternatively you could make sure they are in the same namespace, but I do not recommend that. Also, if these files are in differenet projects make sure your UI project has a reference to the EntityModel project.

Edit: To try to show you what I mean.

Sample Project

Here is a section of one of my projects. Each folder here has a different namespace.

data.abstract
data.concrete
data.entities

If I want to reference a class in another UI project i first need to add a reference to the data assembly to the UI project and then inside the UI project I need to import the namespace ex:

using data.abstract;
using data.entities;
  • When I change the namespace in the edmx-file to the one as in Default.aspx.cs, it doesn't recognize the namespace in the edmx-file. When I try to set "using" in my Default.aspx.cs file, it doesn't pick up the Namespace as used in the edmx-file. So I set "using SteeringWheel;" in my Default.aspx.cs. The compiler doesn't recognize it. – Roy Coumans Jan 21 '15 at 14:36
  • Then you liking need to add an assembly reference to the project that includes that namespace. – Michael Humelsine Jan 21 '15 at 14:37
  • Ok, so I right-click in "References", browse to obj/release/TempPE and add "AcrrualEntityModel.Designer.cs.dll". I can see the reference in Solution Explorer. Still, I can't use SteeringWheelModel. I guess I added the wrong reference? – Roy Coumans Jan 21 '15 at 14:59
  • Add Reference -> Projects -> select your EntityModel Project -> click OK. You should then see your assembly under References in your UI project. – Michael Humelsine Jan 21 '15 at 15:09
  • Thank you for trying to explain. Maybe I need a step-by-step tutorial to add an Entitymodel to an existing SQLServer database. – Roy Coumans Jan 21 '15 at 15:35
  • I can't find the EntityModel-project, because the EntiyModel is in the same Solution. There is nothing to choose from. – Roy Coumans Jan 21 '15 at 15:38
  • Is your default.aspx.cs inside a namespace? If not, you will need to import the name of your project (default assigned namespace) in the code behind or include the code behind in the namespace. Post your default.aspx.cs – Michael Humelsine Jan 21 '15 at 15:57
  • Yes it is in a namespace: – Roy Coumans Jan 21 '15 at 16:23
  • You need to post your default.aspx.cs where the EntityModel is failing. – Michael Humelsine Jan 21 '15 at 16:24
  • >using System; >using System.Collections.Generic; >using System.Linq; >using System.Web; >using System.Web.UI; >using System.Web.UI.WebControls; >namespace Exam70315_Chachp11Les2 >{ > public partial class _Default : System.Web.UI.Page > { > protected void Page_Load(object sender, EventArgs e) > { > > if (!IsPostBack) > { > SteeringWheelModel.SteeringWheelEntities sw = new SteeringWheelModel.SteeringWheelEntities(); > > } > } > } >} – Roy Coumans Jan 21 '15 at 16:25
  • You should be able to directly reference SteeringWheelEntities. – Michael Humelsine Jan 21 '15 at 16:27
  • It doen't recognize "SteeringWheelModel". Sorry for the code. The editor concatenates my lines – Roy Coumans Jan 21 '15 at 16:27
  • That's correct! It does reference it directly. Now a green warning applies with :"No Metadata Documentation Available". However, it is not an error. – Roy Coumans Jan 21 '15 at 16:33
  • if (!IsPostBack) { SteeringWheelEntities sw = new SteeringWheelEntities(); var personQuery = from p in sw.tblPerson orderby p.LastName select p; } – Roy Coumans Jan 21 '15 at 16:35
  • Now I deleted the reference to the dll and all works! No warnings, I have a query running. Thank you all! – Roy Coumans Jan 22 '15 at 09:54