Created
October 27, 2013 17:28
-
-
Save kiyokura/7185377 to your computer and use it in GitHub Desktop.
RazorでのDapperサンプル(用意した型で受け取る場合)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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