Base solution for your next web application
Open Closed

OData - cannot create AbpODataEntityController on entity with long id #11002


User avatar
0
visility created

ASP.NET CORE MVC & jQuery .NET 6.0 v11.1.0

hi Your class: public abstract class AbpODataEntityController<TEntity> : AbpODataEntityController<TEntity, int> where TEntity : class, IEntity<int> { protected AbpODataEntityController(IRepository<TEntity> repository) : base((IRepository<TEntity, int>)repository) { } } is locked to int. But we have an entity with id of type long - and therefore cannot create a controller for that entity. What can we do?

Thanks,


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @visility

    You can define your controller as shown below;

    public class MyOdataController : AbpODataEntityController<MyEntity, long>, ITransientDependency
        {
            public MyOdataController(IRepository<MyEntity, long> repository) : base(repository)
            {
              
            }
        }
    
  • User Avatar
    0
    visility created

    thank you - i was hoping that implementing that additional odata controller would do the job, however I still get a strange problem when i use expand to include records from related table.

    My odata request looks like this: https://localhost:44302/odata/MetricHead?$filter=MetricId eq '7000007112.netatmo_1.02:00:00:00:73:82.States/Temperature'&$Expand=MetricRecords($top=10)

    But the result is terminated just as the related data should come i MetricRecords array:

    {"@odata.context":"https://localhost:44302/odata/$metadata#MetricHead(MetricRecords())","value":[{"MetricId":"7000007112.netatmo_1.02:00:00:00:73:82.States/Temperature","DataType":10,"TenantId":31,"OrganizationUnitId":null,"GroupId":"4","MetricName":"States/Temperature","DeviceId":"netatmo_1.02:00:00:00:73:82","LocationName":"Ude2","UserLabel":"Udeklima2","UserNote":null,"ObjectProperties":null,"LogType":2,"Unit":9,"Scale":0,"BrickLocation":"NA","BrickMeasurable":"Temperature","BrickEquipment":"Meter","BrickPoint":"MISSING","BrickRelationships":null,"BrickTag":null,"CreatedUTC":"2022-02-08T13:53:30.877+01:00","UpdatedUTC":"2022-03-29T19:23:30.8124695+02:00","UpdatedByUserId":85,"IsDeleted":false,"LogPeriod":60,"Plan":1,"DecimalDegree":"9.478276638304067,55.260628687395695","Latitude":null,"Longitude":null,"Altitude":null,"Id":7443,"MetricRecords":[

    I do net get any errors: INFO 2022-04-02 16:14:54,252 [orker] Microsoft.AspNetCore.Hosting.Diagnostics - Request finished HTTP/1.1 GET https://localhost:44302/odata/MetricHead?$filter=Id%20eq%206748&$expand=MetricRecords($top=10)%0A - - - 200 - application/json;+odata.metadata=minimal;+odata.streaming=true 13643.9946ms;

    (My MetricHead do have Expand in options) Do you have an idea? Thank you

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @visility

    Is it possible to share your project with [email protected] ? Checking this on the project will be better I guess.