Reputation: 624
Let me clear the question with an example.
If I want to query a complex data gathered from different table in SQL Server View, that look something like this (assume that the view is very complex)
SELECT e.ID, e.etc s.etc
FROM TableE AS e
LEFT OUTER JOIN TableS AS s ON e.ID = s.NIP
WHERE ID > 1000
Then on C# I query it like this:
new SqlCommand("SELECT * FROM VeryComplexView", connection)
IS the above way better than doing like this, without creating the view first:
var query = @"SELECT e.ID, e.etc s.etc
FROM TableE AS e
LEFT OUTER JOIN TableS AS s ON e.ID = s.NIP
WHERE ID > 1000";
new SqlCommand(query, connection)
The view is actually more complex than the example above.
Upvotes: 1
Views: 295
Reputation: 935
To achieve better performance and more secure approach, please create stored procedure, and include yuor query in it. Then call your procedure from C# code.
Upvotes: 1