score:1
i can't seem to find such warning in ef core documentation. and the (sort of) funny things is that the ef core 2.1 query translator itself does not parameterize the generated sql in
values clauses. which can be seen if you replace the .fromsql
line of your query with
.where(x => artnum.contains(x.artikelnummer)
which btw is the linq to entities equivalent of your query which translates and executes just fine, so i don't know why you bother with fromsql
in this particular case.
but anyway, you can parameterize the fromsql
query by including {0}
, {1}
etc. placeholders inside the sql string and pass values through params object[] parameters
:
as with any api that accepts sql it is important to parameterize any user input to protect against a sql injection attack. you can include parameter place holders in the sql query string and then supply parameter values as additional arguments. any parameter values you supply will automatically be converted to a dbparameter
in your case it could be like this:
var placeholders = string.join(",", atrnum.select((v, i) => "{" + i + "}"));
var values = atrnum.cast<object>().toarray();
.fromsql("select * from table where artikelnummer in (" + placeholders + ")", values)
Source: stackoverflow.com
Related Query
- warning EF1000. What the best way to write parameters in "IN" statement?
- What is the best way to write queries in Entity Framework
- What is the best way to write a two column query in LINQ to Entity 6? And save the results to two different variables?
- What is the best way to make a LINQ-to-XML statement dynamic?
- What is the best way to check IQueryable result set is null
- What is the easiest way to find the LINQ statement for a SQL statement
- What is the best way to check two List<T> lists for equality in C#
- What's the best way to write [0..100] in C#?
- What is the best way to mix VB.NET's Option Strict and the new Option Infer directives?
- What is the best way to check and retrieve the first item of a collection?
- What is the best way to create strongly typed LINQ queries from some given strings, via reflection
- What is the best way to cast each item in a LINQ to Entities query to an interface?
- What is the best way to merge two objects during runtime using C#?
- What is the best way to query a database for records within n miles of a zip code?
- What is the best way to separate string using string.format() function or LINQ ?
- What is the return type for a anonymous linq query select? What is the best way to send this data back?
- What is the best way in linq to calculate the percentage from a list?
- what is the best way to convert one dictionary to another
- What is the best way to get the level from a tree data structure using LINQ?
- What is the best way to transparently log changes to objects when using LINQ-to-SQL?
- What are the two ways I can write this statement with LINQ?
- What is the best way to optimize or "tune" LINQ expressions?
- What is the best way to find all dependent children in a IEnumerable collection
- What is the best way to get the percentage for an object in linq list and map it to JSON?
- What is the best way to sort using a GridView and LINQ?
- What is the best way to group groupings of groupings?
- Code Cleanup: Best way to split long statement over multiple lines
- In C#, What is the best way to see if a list contains another list?
- What is the best way to sort a List of objects with a start value?
- What is the best way to count collection of dates by quarter?
More Query from same tag
- How to use LINQ to set null values last in ordered list of integers
- How to use let to define a new set of data within a LINQ query?
- How to project enum to id, value anon type?
- LINQ Equivalent MYSQL Query
- Simple Linq to XML Query Doesn't Work
- Return an IQueryable that joins two tables
- Linq to EF Search for a string that does not start with a Letter
- Lost join when self-joining a table on the same field
- Understanding the extension ElementAt(index)
- Bind chart using linq
- How to efficiently grab results from Linq with or without user input params
- Take every 2nd object in list
- WCF Service Method is not Working
- Entity Framework - Unable to create a constant value of type
- How create groups with evenly sizes
- Using linq to update a composite key field
- Query does not return child collections
- Compare two objects based on criteria
- WCF Data Service Operation cast issue
- To get records in comma seperated List LINQ to Entities
- List where Clause with Remove
- C# Linq Lambda Left Outer Join
- Entity Framework 6. Query performance continues to degrade
- How to make my linq to entities query for sum faster
- Linq Select New List Property Null Check
- Contains matches on pairs of items
- LINQ String comparison with NULL handling
- What can I do with the IEnumerable(of T) result except iterate over it?
- Linq with Optional Where clauses
- linq operator like * (asterisk) in sql