locked
Real world Example of POCO objects RRS feed

  • Question

  • User769474054 posted

    Hi,

    I am rewriting my legacy ASP.NET Web FOrms app to Angular 2. I am wondering if I need to use POCO objects and not sure how and why to use them. Do I really need them or how do I know if I have to use them any real world example would be helpful to understand me better. I couldn't find many over the web.

    Friday, July 27, 2018 5:37 PM

All replies

  • User1120430333 posted

    I don't see how a .NET class called POCO has anything to do with Angular with Angular being a JavaScript solution. Jumping from ASP.NET Web forms to Angular is a big leap.  Making that jump is benefiting you how?

    https://en.wikipedia.org/wiki/Plain_old_CLR_object

    Friday, July 27, 2018 9:29 PM
  • User769474054 posted

    Hi DA 924,

    we are using latesdt opensource front end frameworks to migrate our apps. So we chose Angular 2. So, I am restructring the wole App into UI layer (Angular), WebAPI (Service), BLL and DAL.

    Thats when I am wondering if I need to use Plan Old CLR objects to represent data in database or  just stick with edmx classes that were generated by Visual studio. Hope it made some better context

    Friday, July 27, 2018 10:21 PM
  • User475983607 posted

    It's not recommended to serialize EDMX types regardless of the client or server framework.

    Friday, July 27, 2018 10:30 PM
  • User1120430333 posted

    The POCO is not meant for traveling between processes or layers. The DTO is meant for that.

    https://en.wikipedia.org/wiki/Data_transfer_object

    https://www.codeproject.com/Articles/1050468/Data-Transfer-Object-Design-Pattern-in-Csharp

    The DAL is  using the DAO pattern, DTO pattern and  DAO doing CRUD with the database using EF. The DTO(s) are in a classlib project and all projects that need to know about the DTO(s) set project refernce to the Entities classlib project. 

    using System.Collections.Generic;
    using DAL;
    using Entities;
    using Microsoft.AspNetCore.Mvc;
    
    namespace ProgMgmntCore2Api.Controllers
    {
        [Produces("application/json")]
        [Route("api/[controller]")]
        [ApiController]
    
        public class ProjectController : ControllerBase, IProjectController
        {
            private readonly IDaoProject _daoProject;
    
            public ProjectController(IDaoProject daoProject)
            {
                _daoProject = daoProject;
            }
    
            [HttpGet]
            [Route("GetProjById")]
            public DtoProject GetProjectById(int id)
            {
                return  _daoProject.GetProjectById(id);
            }
            
            [HttpGet]
            [Route("GetProjsByUserId")]
            public List<DtoProject> GetProjectsByUserId(string userid)
            {
                return _daoProject.GetProjectsByUserId(userid);
            }
    
            [HttpPost]
            [Route("CreateProject")]
            public void Post_CreateProject(DtoProject dto)
            {
                _daoProject.CreateProject(dto);
            }
    
            [HttpPost]
            [Route("DeleteProject")]
            public void Post_DeleteProject(int id)
            {
                _daoProject.DeleteProject(id);
            }
    
            [HttpPost]
            [Route("UpdateProject")]
            public void Post_UpdateProject(DtoProject dto)
            {
                _daoProject.UpdateProject(dto);
            }
        }
    }
    

    Saturday, July 28, 2018 11:37 AM