Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Linq语句有10个错误_C#_Linq - Fatal编程技术网

C# Linq语句有10个错误

C# Linq语句有10个错误,c#,linq,C#,Linq,我的Linq声明如下: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace TourService_Someone { class AuthenticateUser : IAuthenticateUser { string IAuthenticateUser.Aut

我的Linq声明如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TourService_Someone
{
    class AuthenticateUser : IAuthenticateUser
    {
        string IAuthenticateUser.AuthenticateUser(User user)
        {
            AbcTourContext con = new AbcTourContext();

            User returnedUser = from u in con.Users
                                where u.username == user.username and u.password == user.password
                                select u;

            if (returnedUser == null)
            {
                return "Login Failed!";
            }
            else
            {
                return "Login Success!";
            }
        }
    }
}

请注意,我对Linq是个新手

它有以下错误:

查询主体必须以select子句或group by子句结尾。此错误显示在语句中的and关键字上

);预期。此错误显示在语句中的and关键字上

找不到类型命名空间和。是否缺少using指令或程序集引用?。此错误显示在语句中的and关键字上

范围变量“u”与先前的声明“u”冲突。此错误显示在其第一次出现的u上

);预期。此错误显示在u.password字段中

名称密码在当前上下文中不存在。此错误显示在u.password字段中

);预期。此错误显示在select关键字上

找不到类型命名空间select。是否缺少using指令或程序集引用?。此错误显示在select关键字上

此范围中已定义名为“u”的局部变量或函数。此错误显示在最后一次出现“u”时

已声明变量“u”,但从未使用过。此错误显示在最后一次出现“u”时

变量con是实体框架的DBContext,它是我的上下文,从中我得到了一个DBSet。用户作为参数在Linq语句所在的方法中传递

我不知道为什么会发生这些错误。我以前写过Linq声明,它们都很好。但是,这是另外一回事

我是否忽略了一些非常简单的事情

编辑:

以下是我的用户模型:

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;

namespace TourService_Someone
{
    [Table("User")]
    public partial class User
    {
        [Key]
        [Required]
        [StringLength(50)]
        public string username { get; set; }

        [Required]
        [StringLength(50)]
        public string password { get; set; }
    }
}


好的,我在.net Fiddle中复制了这个,它应该可以正常工作:

User returnedUser = (from u in con.Users
                                where u.username == user.username && u.password == user.password
                                select u).First();

而不是和,我们使用&&

在con中尝试User returnedUser=from u。其中u.username==User.username和u.password==User.password的用户首先选择u@zaitsman不,同样的错误仍然存在。另外,它不能识别第一种方法;User returnedUser=来自con.Users中的u.username==User.username&&u.password==User.password选择u.First;。您应该使用&&而不是和。看:我已经试过了,但是没有第一种方法,它不起作用。这就是为什么我没有看到这个解决方案。不过谢谢你,它解决了我的问题。@Compilerv2作为补充说明,你不应该在数据库中以明文形式存储密码。用Salt和IV对它们进行散列,并存储散列,Salt和IV,但不存储算法名称。嗯,我这样做是作为大学作业,教授不会试图破解我的应用程序;。