I have a project that I am working on. I decided to use Entity Framework with DBContext generator (to have persistance unaware objects) and I am now stuck with some issues.
Here is how I set my solution:
Solution:
- MyProject (my web app project)
- BusinessObjects (project) contains myproject.tt file with all objects (entities) inside. Each one in separate .cs file.
- DataAccess (project) contains myproject.edmx, myproject.Context.tt files
Here is my question: (I am new to all of this)
Let's say I have object (entity) Job and I want to define select, insert, update and delete methods on this object. Where do I do that? I tried to create folder Custom (where I would put all my customizations) inside BusinessObjects project. Then, I wanted to define my methods there but I don't know how to create new instance of ctx (context) object.
Here is my code:
namespace BusinessObjects
{
public partial class Job
{
public Job GetJob(Guid Id) {
using (var ctx = new BestGigEntities())
}
return null; //for now
}
}
}
The error message I get is that BestGigEntities does not exist in namespace. BestGigEntities should live in BusinessObjects, but somehow it is not visible when I tried to access it from withing BusinessObject project. But I can see it from my main web project. In myproject.Context.tt I have BusinessObjects specified as Custom Tool Namespace. Why I can't see it?
I have checked my myproject.Context.cs file and I can see
public partial class BestGigEntities : DbContext
{
public BestGigEntities()
: base("name=BestGigEntities")
{
. ...
Everything seems to be ok. I am almost sure I added all references properly. I am thinking maybe I am trying to define these methods on wrong place?
BestGigEntities is visible from my web project and I can use it from there.
Any help is appreciated.