微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SQL查询结果未在.net API中正确显示

如何解决SQL查询结果未在.net API中正确显示

我有一个调用stored-procedureSQL查询

存储过程在sql server中正常工作。但是在.NET部分的foreach (var item in query_pre)中,我得到了错误的结果。

.NET.中,我有以下代码

 public partial class get_active_call_info_ids
    {
        public int call_id { get; set; }
        public List<int> call_info_id { get; set; }
        public int call_info_timing_id { get; set; }
        public List<System.DateTime> dateOfBirth { get; set; }
        public List<string> patientName { get; set; }
        public List<string> patientId { get; set; }
        public string station_name { get; set; }

        public get_active_call_info_ids()
        {
            call_info_id = new List<int>();
            dateOfBirth = new List<System.DateTime>();
            patientName = new List<string>();
            patientId = new List<string>();
        }
    }
    public class CallRootObject
    {
        public List<get_active_call_info_ids> Calls { get; set; }
        public int StatusCode { get; set; }

        public CallRootObject()
        {
            Calls = new List<get_active_call_info_ids>();
        }
    }

                    var query_pre = entities.Database.sqlQuery<get_active_call_info_id_Result>("exec [dbo].[get_active_call_info_id] @user_id",new sqlParameter("user_id",u_id))
                        .ToList();

 //Create objects of classes to handle information
                    var queryItem = new get_active_call_info_ids();
                    var queryItems = new CallRootObject();

                    //Initialize parameters
                    int call_id_local = query_pre[0].call_id;
                    int prevIoUs_call_id_local = query_pre[0].call_id;

                    //Counter to control data manipulation

                    foreach (var item in query_pre)
                    {
                        call_id_local = item.call_id;
                        //System.Diagnostics.Debug.WriteLine(item.ToString());

                        
                            queryItem.call_info_id.Clear();
                            queryItem.patientId.Clear();
                            queryItem.patientName.Clear();
                            queryItem.dateOfBirth.Clear();
                        }

                        queryItem.call_id = item.call_id;
                        queryItem.call_info_id.Add(item.call_info_id);
                        queryItem.call_info_timing_id = item.call_info_timing_id;
                        queryItem.patientId.Add(item.patientId);
                        queryItem.patientName.Add(item.patientName);
                        queryItem.dateOfBirth.Add(item.dateOfBirth);
                        queryItem.station_name = item.station_name;

                    };

我在stored-procedure中的sql server运行正常:

enter image description here

但是,API的结果如下:

"{\"Calls\":[{\"call_id\":91390,\"call_info_id\":[20],\"call_info_timing_id\":30,\"dateOfBirth\":[\"2020-09-23T17:54:04.817\"],\"patientName\":[\"N/A\"],\"patientId\":[\"987654\"],\"station_name\":\"ΣΤΑΘΜΟΣ ΠΑΛΙΟΥ ΝΟΣ. ΛΕΜΕΣΟΥ\"},{\"call_id\":91391,\"station_name\":\"ΣΤΑΘΜΟΣ ΠΑΛΙΟΥ ΝΟΣ. ΛΕΜΕΣΟΥ\"}],\"StatusCode\":1}"

解决方法

我找到了解决方案。而不是拥有

queryItem.call_info_id.Clear();
queryItem.patientId.Clear();
queryItem.patientName.Clear();
queryItem.dateOfBirth.Clear();

我用过:

queryItem = new get_active_call_info_ids(); 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。