Sql server Wcf服务中的Linq到Sql对话

Sql server Wcf服务中的Linq到Sql对话,sql-server,linq,wcf,Sql Server,Linq,Wcf,您能否在sql查询之后向linq提供一个答案。我对linq有一些了解,但对sql reader对象感到困惑 public AccountBalanceRequest AccountBalanceCheek(AccountBalanceRequest accountNumber) { using (SqlConnection conn = new SqlConnection(ConnectionString)) { conn.Ope

您能否在sql查询之后向linq提供一个答案。我对linq有一些了解,但对sql reader对象感到困惑

 public AccountBalanceRequest AccountBalanceCheek(AccountBalanceRequest accountNumber)
    {
        using (SqlConnection conn = new SqlConnection(ConnectionString))
        {
            conn.Open();

            var cmd = new SqlCommand("SELECT  Account_Type,Account_Fees,Account_Balance,Over_Draft_Limit FROM Current_Account_Details WHERE Account_Number = '" + accountNumber.Account_Number + "'", conn);
            cmd.CommandType = CommandType.Text;

            var reader = cmd.ExecuteReader();
            //read the result of the execute command.
            while (reader.Read())
            {
                //assuming that your property is the same as your table schema. refer to your table schema Current_Account_Details
                accountNumber.Account_Type = reader["Account_Type"].ToString();
                accountNumber.Account_Fee = reader["Account_Fees"].ToString();
                accountNumber.Account_Balance = reader["Account_Balance"].ToString();
                accountNumber.Over_Draft_Limit = reader["Over_Draft_Limit"].ToString();
            }
            return accountNumber;
        }
    }

首先,必须有DbContext,必须使用它进行实例化(通常做法):

确保已创建对象数据


我不知道你文章的其他部分,但这将是如何编写LINQ2实体查询的一般思路。

首先,你必须有DbContext,你必须使用它进行实例化(通常做法):

确保已创建对象数据


我不知道你文章的另一部分,但这将是如何编写LINQ2实体查询的一般思路。

首先,你的代码非常危险,容易受到攻击。第二,您的问题是什么,提供的代码是否有错误,或者它是否没有返回您需要的内容?我想将此查询转换为linq。没有错误。请从此处开始阅读:。我们不能在这里开始LINQ课程。我并没有要求你们在这个网站开始上课。我问的是如何在linq@gert annold中使用sql reader对象这个问题没有意义。如果要将SQL查询转换为LINQ,首先选择要使用的ORM。一旦你这样做了,你就不会再和DbReaders打交道了。首先,你的代码非常危险,容易受到攻击。第二,您的问题是什么,提供的代码是否有错误,或者它是否没有返回您需要的内容?我想将此查询转换为linq。没有错误。请从此处开始阅读:。我们不能在这里开始LINQ课程。我并没有要求你们在这个网站开始上课。我问的是如何在linq@gert annold中使用sql reader对象这个问题没有意义。如果要将SQL查询转换为LINQ,首先选择要使用的ORM。一旦你这样做了,你就不会再和DbReaders打交道了。非常感谢@rob非常感谢@rob
using (DbContext db = new DbContext())
{
    var results = (from ad in db.Current_Account_Details
                  where ad.Account_Number == accountNumber.Account_Number
                  select ad).ToList();
}