使用 ADO.NET 开发的 Web API 2 方法性能不佳,耗时 53 秒

Web API 2 method developed using ADO.NET is not performing well, takes 53 seconds

我正在使用 Asp.Net Web API2 为 Android 应用创建 API。有一种方法可以从 table 中获取成员数据。我正在根据 arrangements(int) 和 name(string) 对成员进行排序和列出。第一个按值不为 0 的排列排序。然后按值为 0 的名称排序。一切正常,但查询执行耗时 53234 毫秒,如 postman.PErformance 所示,当我使用 EF6 时最差。我使用 live URL 而不是在本地主机上对其进行了测试。我有云服务器。请检查并帮助我提高性能。只有大约 1000 rows/records。还有另一个 query/stored 程序,它根据经纬度列出附近的成员,执行时间几乎不到 2 秒。如果您需要更多信息,请与我们联系。谢谢

API 方法

    [HttpGet]
    [ActionName("GetAllMembersOfClub")]
    public APIResult GetAllMembersOfClub()
    {
        APIResult apiResult = new APIResult();

        List<MemberData> lstMember = new List<MemberData>();

        var cmd = new SqlCommand("Rotary1.usp_GetMembersWithArrangements", conn);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@clubId", DbType.Int32).Value = clubID;       
        conn.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            var objMember = new MemberData();


            objMember.CountryCode = dr["CountryCode"].ToString();
            objMember.ClubName = dr["ClubName"].ToString();

            objMember.Name = dr["name"].ToString();
            objMember.Classification = dr["Classification"].ToString();
            objMember.OfficeAdrs1 = dr["OfficeAdrs1"].ToString();
            objMember.OfficeAdrs2 = dr["OfficeAdrs2"].ToString();
            objMember.OfficeAdrs3 = dr["OfficeAdrs3"].ToString();
            objMember.ResAdrs1 = dr["ResAdrs1"].ToString();
            objMember.ResAdrs2 = dr["ResAdrs2"].ToString();
            objMember.ResAdrs3 = dr["ResAdrs3"].ToString();
            objMember.Spouse = dr["Wife"].ToString();
            objMember.Phone = dr["Phone"].ToString();
            objMember.Mobile = "+" + dr["CountryCode"].ToString() + dr["Mobile"].ToString();
            objMember.EmailId = dr["EmailId"].ToString();

            objMember.Since = dr["Since"].ToString();
            objMember.Title1 = dr["title1"].ToString();
            objMember.Title2 = dr["title2"].ToString();
            objMember.Title3 = dr["title3"].ToString();
            objMember.Title4 = dr["title4"].ToString();
            objMember.PostHeld = dr["PostHeld"].ToString();
            objMember.Imgg = dr["imgg"].ToString();


            objMember.Anniversary = dr["Aniversary"].ToString();
            objMember.Position = dr["Position"].ToString();
            objMember.Ophone = dr["ophone"].ToString();
            objMember.Children = dr["Children"].ToString();

            objMember.Spouse = dr["Wife"].ToString();
            objMember.Latitude = dr["Latitude"].ToString();
            objMember.Longitude = dr["Longitude"].ToString();
            objMember.Mobile10 = dr["mobile10"].ToString();
            objMember.Mobile2 = dr["mobile2"].ToString();
            objMember.Mobile3 = dr["mobile3"].ToString();
            objMember.Mobile4 = dr["mobile4"].ToString();
            objMember.Mobile5 = dr["mobile5"].ToString();
            objMember.Mobile6 = dr["mobile6"].ToString();
            objMember.Mobile7 = dr["mobile7"].ToString();
            objMember.Mobile8 = dr["mobile8"].ToString();
            objMember.Mobile9 = dr["mobile9"].ToString();
            objMember.Noti = dr["noti"].ToString();
            objMember.Arrange = dr["arrange"].ToString();
            try
            {
                objMember.DOB = Convert.ToDateTime(dr["DOB"].ToString()).ToString("dd-MM-yyy");
            }
            catch (Exception)
            {
                objMember.DOB = "";
            }



            if (!string.IsNullOrWhiteSpace(objMember.Mobile2) || objMember.Mobile2 != "")
            {
                objMember.Mobile2 = "+" + dr["CountryCode"].ToString() + dr["mobile2"].ToString();
            }

            if (!string.IsNullOrWhiteSpace(objMember.Mobile3) || objMember.Mobile3 != "")
            {
                objMember.Mobile3 = "+" + dr["CountryCode"].ToString() + dr["mobile3"].ToString();
            }

            if (!string.IsNullOrWhiteSpace(objMember.Mobile4) || objMember.Mobile4 != "")
            {
                objMember.Mobile4 = "+" + dr["CountryCode"].ToString() + dr["mobile4"].ToString();
            }

            if (!string.IsNullOrWhiteSpace(objMember.Mobile5) || objMember.Mobile5 != "")
            {
                objMember.Mobile5 = "+" + dr["CountryCode"].ToString() + dr["mobile5"].ToString();
            }

            if (!string.IsNullOrWhiteSpace(objMember.Mobile6) || objMember.Mobile6 != "")
            {
                objMember.Mobile6 = "+" + dr["CountryCode"].ToString() + dr["mobile6"].ToString();
            }

            if (!string.IsNullOrWhiteSpace(objMember.Mobile7) || objMember.Mobile7 != "")
            {
                objMember.Mobile7 = "+" + dr["CountryCode"].ToString() + dr["mobile7"].ToString();
            }

            if (!string.IsNullOrWhiteSpace(objMember.Mobile8) || objMember.Mobile8 != "")
            {
                objMember.Mobile8 = "+" + dr["CountryCode"].ToString() + dr["mobile8"].ToString();
            }

            if (!string.IsNullOrWhiteSpace(objMember.Mobile9) || objMember.Mobile9 != "")
            {
                objMember.Mobile9 = "+" + dr["CountryCode"].ToString() + dr["mobile9"].ToString();
            }

            if (!string.IsNullOrWhiteSpace(objMember.Mobile10) || objMember.Mobile10 != "")
            {
                objMember.Mobile10 = "+" + dr["CountryCode"].ToString() + dr["mobile10"].ToString();
            }
            lstMember.Add(objMember);
        }
        dr.Close();
        conn.Close();

         cmd = new SqlCommand("Rotary1.usp_GetMembersWithArrangements1", conn);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@clubId", DbType.Int32).Value = clubID;
        conn.Open();
        dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            var objMember = new MemberData();


            objMember.CountryCode = dr["CountryCode"].ToString();
            objMember.ClubName = dr["ClubName"].ToString();

            objMember.Name = dr["name"].ToString();
            objMember.Classification = dr["Classification"].ToString();
            objMember.OfficeAdrs1 = dr["OfficeAdrs1"].ToString();
            objMember.OfficeAdrs2 = dr["OfficeAdrs2"].ToString();
            objMember.OfficeAdrs3 = dr["OfficeAdrs3"].ToString();
            objMember.ResAdrs1 = dr["ResAdrs1"].ToString();
            objMember.ResAdrs2 = dr["ResAdrs2"].ToString();
            objMember.ResAdrs3 = dr["ResAdrs3"].ToString();
            objMember.Spouse = dr["Wife"].ToString();
            objMember.Phone = dr["Phone"].ToString();
            objMember.Mobile = "+" + dr["CountryCode"].ToString() + dr["Mobile"].ToString();
            objMember.EmailId = dr["EmailId"].ToString();

            objMember.Since = dr["Since"].ToString();
            objMember.Title1 = dr["title1"].ToString();
            objMember.Title2 = dr["title2"].ToString();
            objMember.Title3 = dr["title3"].ToString();
            objMember.Title4 = dr["title4"].ToString();
            objMember.PostHeld = dr["PostHeld"].ToString();
            objMember.Imgg = dr["imgg"].ToString();


            objMember.Anniversary = dr["Aniversary"].ToString();
            objMember.Position = dr["Position"].ToString();
            objMember.Ophone = dr["ophone"].ToString();
            objMember.Children = dr["Children"].ToString();

            objMember.Spouse = dr["Wife"].ToString();
            objMember.Latitude = dr["Latitude"].ToString();
            objMember.Longitude = dr["Longitude"].ToString();
            objMember.Mobile10 = dr["mobile10"].ToString();
            objMember.Mobile2 = dr["mobile2"].ToString();
            objMember.Mobile3 = dr["mobile3"].ToString();
            objMember.Mobile4 = dr["mobile4"].ToString();
            objMember.Mobile5 = dr["mobile5"].ToString();
            objMember.Mobile6 = dr["mobile6"].ToString();
            objMember.Mobile7 = dr["mobile7"].ToString();
            objMember.Mobile8 = dr["mobile8"].ToString();
            objMember.Mobile9 = dr["mobile9"].ToString();
            objMember.Noti = dr["noti"].ToString();
            objMember.Arrange = dr["arrange"].ToString();
            try
            {
                objMember.DOB = Convert.ToDateTime(dr["DOB"].ToString()).ToString("dd-MM-yyy");
            }
            catch (Exception)
            {
                objMember.DOB = "";
            }



            if (!string.IsNullOrWhiteSpace(objMember.Mobile2) || objMember.Mobile2 != "")
            {
                objMember.Mobile2 = "+" + dr["CountryCode"].ToString() + dr["mobile2"].ToString();
            }

            if (!string.IsNullOrWhiteSpace(objMember.Mobile3) || objMember.Mobile3 != "")
            {
                objMember.Mobile3 = "+" + dr["CountryCode"].ToString() + dr["mobile3"].ToString();
            }

            if (!string.IsNullOrWhiteSpace(objMember.Mobile4) || objMember.Mobile4 != "")
            {
                objMember.Mobile4 = "+" + dr["CountryCode"].ToString() + dr["mobile4"].ToString();
            }

            if (!string.IsNullOrWhiteSpace(objMember.Mobile5) || objMember.Mobile5 != "")
            {
                objMember.Mobile5 = "+" + dr["CountryCode"].ToString() + dr["mobile5"].ToString();
            }

            if (!string.IsNullOrWhiteSpace(objMember.Mobile6) || objMember.Mobile6 != "")
            {
                objMember.Mobile6 = "+" + dr["CountryCode"].ToString() + dr["mobile6"].ToString();
            }

            if (!string.IsNullOrWhiteSpace(objMember.Mobile7) || objMember.Mobile7 != "")
            {
                objMember.Mobile7 = "+" + dr["CountryCode"].ToString() + dr["mobile7"].ToString();
            }

            if (!string.IsNullOrWhiteSpace(objMember.Mobile8) || objMember.Mobile8 != "")
            {
                objMember.Mobile8 = "+" + dr["CountryCode"].ToString() + dr["mobile8"].ToString();
            }

            if (!string.IsNullOrWhiteSpace(objMember.Mobile9) || objMember.Mobile9 != "")
            {
                objMember.Mobile9 = "+" + dr["CountryCode"].ToString() + dr["mobile9"].ToString();
            }

            if (!string.IsNullOrWhiteSpace(objMember.Mobile10) || objMember.Mobile10 != "")
            {
                objMember.Mobile10 = "+" + dr["CountryCode"].ToString() + dr["mobile10"].ToString();
            }


            lstMember.Add(objMember);
        }

        dr.Close();
        conn.Close();

        apiResult.ReturnData = lstMember;
        apiResult.ReturnCode = "1";
        apiResult.ReturnMessage = "success";

        return apiResult;
    }

Queries/Stored 程序

USE [myDb]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE Procedure [Rotary1].[usp_GetMembersWithArrangements]    
@clubId INT    
As    
BEGIN     
BEGIN       
 select * from main where arrange<>0 and club=@clubId order by arrange desc  
END           
END
GO

第二步

USE [myDb]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE Procedure [Rotary1].[usp_GetMembersWithArrangements1]    
@clubId INT    
As    
BEGIN     
BEGIN       
select * from main where arrange=0 and club=@clubId order by name   
END           
END
GO

下面是table架构

CREATE TABLE [dbo].[main](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [title1] [varchar](max) NULL,
    [title2] [varchar](max) NULL,
    [title3] [varchar](max) NULL,
    [title4] [varchar](max) NULL,
    [Name] [varchar](max) NULL,
    [Classification] [varchar](max) NULL,
    [position] [varchar](max) NULL,
    [PostHeld] [varchar](max) NULL,
    [OfficeAdrs1] [text] NULL,
    [OfficeAdrs2] [text] NULL,
    [OfficeAdrs3] [text] NULL,
    [ophone] [varchar](max) NULL,
    [Phone] [varchar](max) NULL,
    [Mobile] [varchar](max) NULL,
    [EmailId] [varchar](max) NULL,
    [ResAdrs1] [text] NULL,
    [ResAdrs2] [text] NULL,
    [ResAdrs3] [text] NULL,
    [Wife] [varchar](max) NULL,
    [children] [varchar](max) NULL,
    [DOB] [date] NULL,
    [Since] [varchar](max) NULL,
    [imgg] [text] NULL,
    [Aniversary] [varchar](max) NULL,
    [arrange] [int] NULL,
    [club] [int] NULL,
    [noti] [int] NULL,
    [ClubName] [varchar](200) NULL,
    [Latitude] [varchar](200) NULL,
    [Longitude] [varchar](200) NULL,
    [mobile2] [varchar](20) NULL,
    [mobile3] [varchar](20) NULL,
    [mobile4] [varchar](20) NULL,
    [mobile5] [varchar](20) NULL,
    [mobile6] [varchar](20) NULL,
    [mobile7] [varchar](20) NULL,
    [mobile8] [varchar](20) NULL,
    [mobile9] [varchar](20) NULL,
    [mobile10] [varchar](20) NULL,
    [CountryCode] [varchar](10) NULL,
    [Status] [int] NULL CONSTRAINT [DF_main_Status]  DEFAULT ((1)),
 CONSTRAINT [PK_main] PRIMARY KEY CLUSTERED 
(
    [ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
 public List<Member> GetMembers(string name="")
    {
        var param1 = new SqlParameter("@Name",name );
        var result = _Context.Database.SqlQuery<Member>("exec GetMembersList @Name", param1).ToList();
        return result;
    }