The asp.net feature is presenting data that is not fully formed

While working with an Ajax request in JavaScript, I encountered an issue where the data being fetched is repeating in the last three fields. Upon validating the query in the database, it seems that the data retrieved by the Ajax call does not match what is stored. Here are the functions I am using:

In my asp.net application, I have the following function:

[HttpGet]
    public List<Reportes> GetScrapReport(string fecha, string fechaend)
    {
        try {
            var fechaparametro = new SqlParameter("@fecha", fecha);
            var fechafinparametro = new SqlParameter("@fechafin", fechaend);
            var listareport = _context.Reportes.FromSqlRaw($"SELECT DISTINCT idscrap, fecha, modelo, elemento, nombre, numeroparte, cantidad FROM F_GetScrapReport (@fecha, @fechafin)", fechaparametro, fechafinparametro);
            return listareport.ToList();
        }
        catch 
        {
            return new List<Reportes>();
        }
    }

The structure of the Reportes model is as follows:

public class Reportes
{
    [Key]
    public int Idscrap { get; set; }
    public DateTime fecha { get; set; }
    public string modelo { get; set; }
    public string elemento { get; set; }
    public string? nombre { get; set; }
    public string? numeroparte { get; set; }
    public int? cantidad { get; set; }
}

Here's the AJAX JavaScript function I've implemented:

function GetScraptime()
{
    // Function code here
}

The SQL function used to retrieve data from the database is defined as follows:

CREATE FUNCTION F_GetScrapReport (@fecha varchar(20), @fechafin varchar(20))
// SQL Function Code here

When executing the SQL query, the results obtained differ from what is expected and lead to repeated values in certain columns. This inconsistency between the DB data and the displayed results can be seen below:

https://i.sstatic.net/wvKPD.png

This discrepancy is evident in the output where certain columns like nombre, numeroparte, and cantidad exhibit duplicate values which do not align with the actual database records.

https://i.sstatic.net/7fbRZ.png

Answer №1

The issue stemmed from the Reportes data model. I had designated the Idscrap field with [Key], indicating it as the table's identifier. However, in my query, there shouldn't be an identifier as it involves a SELECT with multiple JOIN operations. To address this, I modified the model to include [Keyless], signifying that the query result will not feature an identifier and will reflect the data directly from the database.

[Keyless]
    public class Reportes
    {
        public int  Idscrap { get; set; } 
        public DateTime  fecha { get; set; }
        public string modelo { get;set; }
        public string elemento { get; set; }
        public string? nombre { get; set; }
        public string? numeroparte { get; set; }
        public int?  cantidad { get; set; }
    }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Beautiful Photo: jquery triggers Ajax load completion

To open an AJAX window, I am utilizing prettyPhoto from this link: Here is the link that opens the window: <a rel="prettyPhoto[ajax]" href="resources/comments.php?ajax=true&width=500&height=460&projectid=<?php echo $result['id&apos ...

Validating a string with Hapi Joi validation for singles

Looking to perform basic validation on a single string, specifically the request header X-Value. Here's what I have tried. The issue I'm facing is that it always returns 'success' even when there is no X-Value header present. const ...

Tips for setting up the information in a Bootstrap popover

I am currently working on a Google web app that involves Google Sheets data. My objective is to have the data displayed when hovering over a button, but instead, the data appears directly on the button without the hover display. What might I have done in ...

Error 404: Troubleshooting an Azure Issue with Custom TrueType Font in .NET MVC 5

I am encountering an issue that has been previously addressed. Despite implementing the suggested solutions, the problem persists. In an effort to enhance my project, I downloaded two custom ttf fonts called Monterey and Bakery. Both fonts have been succ ...

Verify if the link includes https:// while using angularjs

In my angular app, there is a lot of data stored in JSON format. [ {"link": "https://stackoverflow.com"}, {"link": "https://stackoverflow.com"}, {"link": "id-aW783D"}, //This data is incorrect {"link": "https://stackoverflow.com"} ] However, the ...

Transform JSON data into a CSV file using JavaScript or C# in an MVC4 framework, then import the data into

I am facing an issue with my website. Currently, when a user submits an application form, an email is sent. However, I would like to create a CSV file containing the form data and then automatically populate my database using this CSV file. Here is my ASP ...

Manipulating toggle buttons using CSS and jQuery

Check out this jsfiddle to see my attempt at creating a toggle switch in the form of a mute button. The toggle button shows the current setting: mute or unmute When hovered over, it displays the alternative setting However, I am encountering an issue wh ...

The issue seems to be that the Ajax and Ruby script is only displaying one record instead of multiple

While attempting an Ajax call using Ruby and Sinatra, I encountered an issue where the query should return multiple rows but only returns one. The ajax script in use is: $(document).ready(function() { $(".showmembers").click(function(e) { e. ...

Utilizing Chrome Context Script plugin to monitor page changes: A step-by-step guide

Currently, I am in the process of creating a basic Chrome extension with the purpose of removing specific DOM elements from a particular website. In my manifest.json file: { "name": "example", "version": "1.0", "description": "example description" ...

What is the process for extracting context or span from an incoming http request in NodeJS without relying on automated tools

I am currently in the process of transitioning my Node.js application from using jaeger-client to @opentelemetry/* packages. Within my Node.js application, I have a basic http server and I aim to generate a span for each response. Previously, with jaeger ...

Can an older style class be inherited from an ECMAScript 6 class in JavaScript?

When I run the code below on Node.js version 4.2.1: 'use strict'; var util = require('util'); class MyClass { constructor(name) { this.name = name; } } function MyDerived() { MyClass.call(this, 'MyDerived'); } ...

I'm having trouble with an error in my React project on VS Code. Can anyone provide guidance

Could you please explain the meaning of this error message: errno: 'ENOENT', code: 'ENOENT', syscall: 'spawn cmd', path: 'cmd', spawnargs: [ '/s', '/c', 'start', '""', ...

having trouble with npm installation of firebase-tools

I am encountering an issue while attempting to set up firebase-tools for my android studio project. Here is the error message that I am facing: Microsoft Windows [Version 10.0.15063] (c) 2017 Microsoft Corporation. All rights reserved. C:\WINDOWS&bs ...

Invoker of middleware and stack functions for Express.js with a focus on capturing the response object

It appears that the expressjs app contains a stack of Layer object Arrays. What function is utilized to pass the I am curious about: When a request is sent from the http client, which function is called first and how are the stack array functions with mi ...

Accessing the value of a hidden field within an ng-repeat loop when binding to an HTML table

I am working on a project where I have an HTML table with data being bound from AngularJS. The structure looks something like this: <tr ng-repeat="item in List| filter: { MachineType: 'Physical' }"> <td>{{item.MachineType}}< ...

Develop a recurring function that takes the foreign key as a parameter

I have a project for my database class in which I need to create a database using SQL Server 2019. I am trying to figure out how to create a function that takes the primary key (PK) from one table and inserts it into the foreign key (FK) of a related table ...

Ensuring that toggleClass is consistently displayed for all visitors to the website

Is there a way to make toggleClass save and remain for all visitors of the site? Although I tried, this method appears to be not working: https://jsfiddle.net/715j94gL/3/ $(function(){ $(".worker").click(function(){ $(this).toggle ...

Guide to selecting multiple rows at once using ng-options in a list

Need assistance with an HTML list: I have a box displaying a list where users can select multiple items to save. The saving and retrieving process is functional as the selectedList stores the user's previous selections, while fullList contains all av ...

Modifying an element's value according to user input: Step-by-step guide

Within my dropdown menu, there is a single option labeled "Others". Upon selecting this option, a textbox appears allowing me to input custom text. Is it possible to dynamically update the value of the <option value="Others">Others</option>, ...

Iterating through an array with conditional statements in JavaScript

I have recently joined this community and am new to coding. Unfortunately, I do not have anyone who can assist me with my issue. I have watched numerous YouTube videos in an attempt to solve the problem myself. I am working on looping through the array bel ...