Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call SQL View Dapper c#

Is there any way to call a sql view by using Dapper c# ?

I already know how to call stored procedures with that, but when it comes to views I have no idea how to do that.

like image 370
Joab Santos Avatar asked Jun 21 '17 20:06

Joab Santos


People also ask

What is DynamicParameters C#?

The DynamicParameters type provides an Add method, enabling you to pass explicit parameters, specifying the datatype, direction and size: var parameters = new DynamicParameters();

What is Dapper SQL?

Dapper is an object–relational mapping (ORM) product for the Microsoft . NET platform: it provides a framework for mapping an object-oriented domain model to a traditional relational database. Its purpose is to relieve the developer from a significant portion of relational data persistence-related programming tasks.


1 Answers

A view works like a table from the perspective of queries, including how filters and parameters work - so something like:

string region = ...
var data = connection.Query<SomeType>(
    "select * from SomeView where Region = @region", new { region }).AsList();
like image 158
Marc Gravell Avatar answered Oct 16 '22 16:10

Marc Gravell