mrahhal / MR.EntityFrameworkCore.KeysetPagination

Keyset/Seek/Cursor pagination for Entity Framework Core.
MIT License
236 stars 12 forks source link

Column Attribute #22

Closed Ngreene-mwks closed 1 year ago

Ngreene-mwks commented 1 year ago

I have an entity with a column that is defined similar to this. The entity is being generated.

public ScheduledService {
   public Guid ScheduledServiceId { get; set; }
   [Column("TBID")]
   public int Tbid { get; set; }
   public DateTime ServiceDate{ get; set; }
}

I am trying to use this sorting builder.Ascending(record => record.ServiceDate).Ascending(record => record.Tbid)

Error: "Detail": "Property 'Tbid' not found on this object." The Column attribute does not seem to be respected, and the query fails.

I thought it was purely the attribute, but I get the same error after manually renaming the Property to TBID.

public ScheduledService {
   public Guid ScheduledServiceId { get; set; }
   public int TBID{ get; set; }
   public DateTime ServiceDate{ get; set; }
}

"Detail": "Property 'TBID' not found on this object."

mrahhal commented 1 year ago

This error happens on the reference, not the entity (error message could be improved). What's your reference object like? This error means there's no property on your reference object that matches the same property on the entity.

Ngreene-mwks commented 1 year ago

async id => await _db.ScheduledServices.FindAsync(Guid.Parse(id.ToString()!)), Actual entitiy Has Guid Id.

So id will contain references to both builder columns? How is that pulled? Looking in doc but not seeing anything, sorry. Thanks for the help!

Ngreene-mwks commented 1 year ago

It was the silly Guid parsing I was trying to do that threw things off. async id => await _db.ScheduledServices.FindAsync(id), Fixed things.

Thanks for pointing in the right direction

Ngreene-mwks commented 1 year ago

The above still failed for getting the next page however. Changed to this: async id => id == null ? null : await _db.ScheduledServices.FindAsync(Guid.Parse(id.ToString()!)),

And ensuring the ViewModel had Tbid on it.

mrahhal commented 1 year ago

Great that you got it working. I see that you're actually using MR.AspNetCore.Pagination there, so id is just simply the entity id as an object, parsed from the HttpContext.Request.Query, code here. And I can see that I'm only trying to parse into an int, otherwise I just keep what the IQueryCollection gives me. And the id there shouldn't be a null, so that's weird. I might have to take another look at this.