don*_*ona 5 asp.net-mvc entity-framework eloquent laravel-4
如何使用Laravel的Eloquent ORM等ASP.NET MVC的实体ORM框架?例如,使用Laravel中的Eloquent,您可以像这样插入新记录:
// instantiate the User model
$user = User();
// set values
$user->email() = 'zanbek@email.com';
$user->name() = 'Zan Bek';
$user->age = '20';
// save
$user->save();
Run Code Online (Sandbox Code Playgroud)
在这里,您可以看到使用Laravel的Eloquent ORM进行数据库查询很有趣。您甚至不需要像数据库的列那样在User模型中放置太多内容。
我的问题是,如何在ASP.NET MVC的实体ORM(如上面的示例代码中所示的Laravel的Eloquent)中进行数据库查询?
你可以尝试使用亚音速
示例 1 - 获取 ListPrice 大于 50.00 美元、类别值为 L 且颜色为黄色的所有产品。
Query qry = Product.CreateQuery().WHERE("ListPrice > 50.00")
.AND("Class = L").AND("Color = Yellow");
IDataReader rdr = qry.ExecuteReader();
while (rdr.Read()) {
Console.WriteLine(rdr[Product.Columns.Name].ToString());
}
Run Code Online (Sandbox Code Playgroud)
示例 2 - 添加新产品。
Currency c = new Currency();
c.CurrencyCode = "CPD";
c.Name = "Code Project Dollar";
c.Save("Some_UserName");
Run Code Online (Sandbox Code Playgroud)
参考
| 归档时间: |
|
| 查看次数: |
2867 次 |
| 最近记录: |