简体   繁体   中英

Problem when calling the Stored Procedure in Console application using EF6

I tried to execute a stored procedure in my console application but what I get is a print of the sentence I want to call.

My stored procedure that I have created:

create proc Checked
@Links nvarchar(MAX)
as
SELECT CASE 
WHEN EXISTS (
    SELECT ID
    FROM News
    WHERE LinkNews = @Links
)
THEN CAST(1 AS BIT)
ELSE CAST(0 AS BIT) END

And the method that I used to call the stored procedure inside the Console Application:

using (DbContextClass db = new DbContextClass())
{
    SqlParameter p = new SqlParameter("@Links", "http://www.newsline-ye.com/news7527.html");
    IEnumerable<New> n = db.Database.SqlQuery<New>("exec Checked @Links", p);
    Console.WriteLine(n);               
}
Console.ReadKey();

My Problem It gives me this output "exec Checked @Links" sentence

Can anyone help me to solve my problem?

List<SqlParameter> sqlParameters = new List<SqlParameter>()
{
    new SqlParameter("Links", p);
}

string query = "EXECUTE Checked @Links";

var result = db.Database.SqlQuery<bool>(query, sqlParameters.ToArray());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM