Skip to content

Instantly share code, notes, and snippets.

@kiyokura
Created October 27, 2013 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiyokura/7185377 to your computer and use it in GitHub Desktop.
Save kiyokura/7185377 to your computer and use it in GitHub Desktop.
RazorでのDapperサンプル(用意した型で受け取る場合)
@using Dapper;
@{
IEnumerable< UserEntity> users;
using( var cn = new System.Data.SqlServerCe.SqlCeConnection("接続文字列"))
{
cn.open();
users = cn.Query<UserEntity>( "SELECT * FROM users");
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<ul>
@foreach( var d in users){
<li> @d.Name : @ d.Email : @d.Age</li>
}
</ul>
</body>
</html>
@functions{
private class UserEntity{
public string Name{get; set;}
public string Email{get; set;}
public string Age{get; set;}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment