Last post Nov 04, 2014 02:28 PM by MetalRules
Nov 04, 2014 01:55 PM|MetalRules|LINK
I need some help. I have a solution with presentation, business and data access layers. I created an Entity Model in the data access layer for the tiny database I'm using (3 tables) and everything went fine. Next, on the business layer, I added a reference
to the data layer and created a singleton class which provides access to the data model as follows:
using Datos; //the data layer
namespace Negocio //business layer
public class EnlaceDatos
//TomaRamosEntities is the EDM on the data layer
private static TomaRamosEntities modeloDatos;
public static TomaRamosEntities ModeloDatos
if (modeloDatos == null)
modeloDatos = new TomaRamosEntities();
//Evitar instanciación (avoid instantiation)
After that I created 3 classes on the business layer that represent the 3 entities of the data model (Alumno, Asignatura, Asignacion). Then, I have to write Create(), Read(), Update() and Delete() methods for each class, but when I was about to finish writing
the Create() method I noticed the ObjectContext's SaveChanges() method wasn't showing up, even though the AddAlumno() method works just fine.
I'd appreciate your help. Perhaps I'm missing something obvious but I'm not seeing it.
Thanks in advance.
Nov 04, 2014 02:11 PM|PatriceSc|LINK
And if you just type .SaveChanges(); and compile the code, the error message is? (the best English translation you can if not already in English). You are 100% sure that
TomaRamosEntities inherits from ObjectContext (or could it be that it wraps an ObjectContext derived class ?)
Not directly related but if this is a web app using a static object will cause issues sooner or later. Unlike a Windows app where it would work, a web app is a single app used by multiple users (rather than a single app instance used each by a single user).
So in a web app ALL users are sharing static data so at some point you'll have multiple users changing the context at the same time which will result in issues...
Nov 04, 2014 02:28 PM|MetalRules|LINK
First of all thanks for your reply. I feel like a complete idiot, as I tried everything but somehow it didn't occur to me to compile and check the errors that came up. Turns out the compiler complained that I didn't have a reference to System.Data.Entity
on my business layer.
I added the reference and now it's working fine.
About the static data, you're right. I'm aware this may not be the proper way to develop a web app, but this is the way it's being passed in the basic .NET class I'm in. We are covering the very basics first and then I suppose we'll be moving on on how to
properly design and implement this kind of thing.
Thanks a lot for your time.