Coder Social home page Coder Social logo

Comments (1)

mchomem avatar mchomem commented on August 20, 2024

UP

@schotime , Is there any documentation or example for this question?

Below is the data model that I want to map to NPoco, but it is not working, the failure occurs in the Employee property, where NPoco is not being able to map, probably because I made a mistake in the configuration or not this is not possible to do:

Entity:

    public class EmployeeTask
    {
        public int Id { get; set; }
        public int EmployeeId { get; set; }
        public Employee Employee { get; set; } // Error here!
        public string Name { get; set; }
        public DateTime CreatedIn { get; set; }
        public DateTime? UpdatedIn { get; set; }
        public DateTime DeadLine { get; set; }
        public bool Done { get; set; }
    }

Mapping:

    public class EmployeeTaskMapping : Map<EmployeeTask>
    {
        public EmployeeTaskMapping()
        {
            this.TableName("EmployeeTask");
            this.PrimaryKey("Id");
            this.Columns(x =>
            {
                x.Column(c => c.Id).WithName("Id");
                x.Column(c => c.EmployeeId).WithName("EmployeeId");
                x.Column(c => c.Employee).Reference(z => z.Id, ReferenceType.Foreign);
                x.Column(c => c.Name).WithName("Name");
                x.Column(c => c.CreatedIn).WithName("CreatedIn");
                x.Column(c => c.UpdatedIn).WithName("UpdatedIn");
                x.Column(c => c.DeadLine).WithName("DeadLine");
                x.Column(c => c.Done).WithName("Done");
            });
        }
    }

What I need to know is, instead of using query with flat SQL to resolve the foreign key issue, if it is possible to use query without using flat SQL, mapping the nested object. In the case of the data layer, I tried this here:

      public async Task<List<EmployeeTask>> Retreave()
      {
              return await _context
                  .Query<EmployeeTask>()
                  .Include(x => x.Employee)
                  .ToListAsync();
      }

... but no result

As I didn't find a practical example on the Wiki, I was testing the methods within the lambda to see what can be done. If you could help with this I would be grateful.
If you need more data, just ask.

from npoco.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.