如何验证使用mvc输入的名称是否存在于数据库

时间:2015-09-04 09:43:02

标签: asp.net-mvc

我正在使用区分大小写的sql server。如何转换数据以便可以在不区分大小写的情况下进行验证

代码: -

using (var kk = new TeamRepository(context))
            {
                var data = new Team();
                var find = kk.GetAll().ToString();

                if (find.Any(x => x.TeamName == apview.TeamName))
                {
                    return false;
                }
                else
                {
                    var _pointrepo = new PointsRepositotry(context);

                    if (image != null)
                    {
                        apview.ImageMimeType = image.ContentType;
                        apview.TeamLogo = new byte[image.ContentLength];
                        image.InputStream.Read(apview.TeamLogo, 0, image.ContentLength);
                    }
                    data.TeamLogo = apview.TeamLogo;
                    data.TeamName = apview.TeamName;
                    data.TeamEmail = apview.TeamEmail;
                    data.Contact_Number = apview.ContactNumber;
                    data.TeamNickName = apview.TeamNickName;
                    data.YearEstablished = apview.YearEstablished;
                    var points = new Points();
                    points.TeamName = apview.TeamName;

                    data.ImageMimeType = apview.ImageMimeType;
                   return kk.Insert(data);
                    //_pointrepo.Insert(points);
                }

1 个答案:

答案 0 :(得分:0)

您可以使用 ToLower

find.Any(x => x.TeamName.ToLower() == apview.TeamName.ToLower())

https://msdn.microsoft.com/en-us/library/e78f86at%28v=vs.110%29.aspx