I am trying to pass a string parameter to a SQL Query , Receiving error below. How can I resolve this? Currently utilizing answer EF Core 2.2, Passing String Parameter to FromSql Statement
Input String was not in a correct format.
public async Task<IEnumerable<Product>> GetProduct(string productKey) { var productParameter = new SqlParameter("@productKey", SqlDbType.VarChar); productParameter.Value = productKey; var productIdList = db.TestDb .FromSql($"select ProductId from dbo.Product product" + " (where product.ProductKey = {productParameter})" ) .Select(c => c.ProductId).ToList(); It is type varchar(6) from ProductKey
Using Net Core 2.2
.Select(c => c.ProductId)since you specify the column name in the query and it's the only column you're returning. Perhaps '.ToList()' ?