Base solution for your next web application
Open Closed

Querying Odata controller returns data from all tenants #11176


0
visility created

MVC verions v11.1.0

Hello I have implemented the Odata like this:

[AbpAuthorize] public class MetricHeadController : AbpODataEntityController<Metric.MetricHead>, ITransientDependency { public MetricHeadController(IRepository<MetricHead> repository) : base(repository) { } }

In startup:

services.AddMvc().AddOData(opts => { var builder = new ODataConventionModelBuilder(); builder.EntitySet<Metric.MetricHead>(nameof(Metric.MetricHead)).EntityType.Expand().Filter().OrderBy().Page().Select(); builder.EntitySet<Metric.MetricRecords>(nameof(Metric.MetricRecords)).EntityType.Filter().OrderBy().Page().Select(); opts.AddRouteComponents("odata", builder.GetEdmModel()); });

However - I get data from all tenants when quering.

What could be wrong? Thank you,


5 Answer(s)
  • 0
    ismcagdas created
    Support Team

    Hi @visility

    1. Do you face this with MetricHead or MetricRecords ?
    2. Could you share both MetricHead and MetricRecords definitions as well ?

    Thanks,

  • 0
    visility created

    hi

    The MetricRecords does not function as you might remember, as the serilization fail because of class member of type object (sql_variant).

    MetricHead:

    [Table("MetricHead")]
    public class MetricHead : Entity&lt;int&gt;, IMustHaveTenant, IMayHaveOrganizationUnit, ISoftDelete
    {       
        public string MetricId { get; set; }
    
        public int DataType { get; set; }
    
        public int TenantId { get; set; }
    
        public long? OrganizationUnitId { get; set; }
    
        public string GroupId { get; set; }
    
        public string MetricName { get; set; }
    
        public string DeviceId { get; set; }
    
        public string LocationName { get; set; }
    
        public string UserLabel { get; set; }
    
        public string UserNote { get; set; }
    
        public string ObjectProperties { get; set; }
    
        public short LogType { get; set; }
    
        public short Unit { get; set; }
    
        public int Scale { get; set; }
    
        public string BrickLocation { get; set; }
    
        public string BrickMeasurable { get; set; }
    
        public string BrickEquipment { get; set; }
    
        public string BrickPoint { get; set; }
    
        public string BrickRelationships { get; set; }
    
        public string BrickTag { get; set; }
    
    
        [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
        public DateTime CreatedUTC { get; set; }
    
        public DateTime UpdatedUTC { get; set; }
    
        public long UpdatedByUserId { get; set; }
    
        public bool IsDeleted { get; set; }
    
        public short LogPeriod { get; set; }
    
        public int? Plan { get; set; }
    
        public string DecimalDegree { get; set; }
    
        public double? Latitude { get; set; }
    
        public double? Longitude { get; set; }
    
        public double? Altitude { get; set; }
    
        public List&lt;MetricRecords&gt; MetricRecords { get; set; }
    
        public MetricHead()
        {
    
        }
    }
    
    And MetricRecords:
    
     [Table("MetricRecords")]
    public class MetricRecords : Entity&lt;long&gt;, ISoftDelete
    {
        public MetricHead MetricHead { get; set; }
    
        [Column("RecordValue", TypeName = "sql_variant")]
        public object RecordValue { get; set; }
    
        public byte RecordValueDataType { get; set; }
    
        public DateTime RecordUTC { get; set; }
    
        public long CreatedByUserId { get; set; }
    
        public bool IsDeleted { get; set; }
    
        public MetricRecords()
        {
    
        }
    }
    
    Thanks,
    
  • 0
    ismcagdas created
    Support Team

    Hi,

    Could you send Abp.TenantId request header and see if it filters the data ?

  • 0
    visility created

    hi, Yes - doing so, I only get related tenant data.

  • 0
    ismcagdas created
    Support Team

    Hi,

    Thanks, you can use it that way. Because, when you make a GET request without any header, the app doesn't know the tenant.