This project is read-only.

Relationships in POCO Entities

Jun 19, 2012 at 2:30 PM

Hey Guys!

I have just setup EF4Templates and generated POCO Entities for my project. I was using normal EF entities before generating POCO entities. I am new to POCO entities and I am sure I have missed a step somewhere. My POCO entites are not picking up the relationships of my DB Model. They were working fine when I was using EF models. For example I have two tables called Appointments and Services. Before using POCO Entities I could access the service of the appointment like this:

var svc = appointment.Service;

But now it returns a null with POCO. What Am I doing wrong? Will greatly appreciate some help. Many Thanks.

Jun 19, 2012 at 4:40 PM

I believe it has something to do with lazy loading, as the property in the EF4Templates is not loaded until you call it, or even it needs to be filled manually.

Jun 19, 2012 at 5:05 PM

I have enabled ProxyCreation in the template as well. But still getting a null value.

Jun 21, 2012 at 11:14 AM

Guys please...tell me how to fix this...My whole software architecture depends on this.

Jun 21, 2012 at 4:32 PM

You can override the code in the property to load the data.

        private Service service = null;

        public Service Service
        {
            get
            {
                if (this.service == null)
                {
                    using (IContext context = new OtherShellEntities())
                    {
                        EntityRepo repo = new EntityRepo(context);

                        this.service = repo.Service.GetById(12);
                    }
                }

                return this.service;
            }
        }