使用 peta poco ORM 在 MVC 应用程序中创建 select 列表
Create select list in MVC application using peta poco ORM
在以前的项目中,我使用 LINQ 查询数据库 table,然后将结果绑定到 MVC 应用程序中的下拉列表。
例如在我看来:
$.getJSON('@Url.Action("ControllerAction")', function(data) {
$(".class").empty();
$.each(data, function (i, c) {
$('.class').append('<option value="' + c.Value + '">' + c.Text + '</option>');
});
$.ajaxSetup({ cache: false}); //If the SQL view changes, ensure that the user does not see old data.
});
在我的控制器中:
Dim ListItems As Generic.List(Of ClassName)
ListItems = (From x In c1 Select (New ClassName With {.Value = x.Value, .Text = x.Value})).ToList
我现在正在学习如何使用 PetaPoco 作为 ORM 来开发类似的应用程序。但是,我正在努力绑定数据库中的数据。
是否可以使用 PetaPoco 实现此目的?
我知道我需要先编写初始查询
var dataContext = new PetaPoco.Database("sqlserverce");
var Something = dataContext.Query<Models.Something.ClassName>("Query");
任何评论都会有很大的帮助
谢谢
詹姆斯.
因为我问这个问题已经有一段时间了,而且我已经解决了我的问题,所以我认为最好 post 这个问题并提供一个正式的答案。
感谢 ClearLogic 的帮助。
使用 .Fetch<> 解决了这个问题,我的最终查询看起来像这样
var x = dataContext.Fetch<ClassNameToRepresentListItems>("DefiningQuery");
在以前的项目中,我使用 LINQ 查询数据库 table,然后将结果绑定到 MVC 应用程序中的下拉列表。
例如在我看来:
$.getJSON('@Url.Action("ControllerAction")', function(data) {
$(".class").empty();
$.each(data, function (i, c) {
$('.class').append('<option value="' + c.Value + '">' + c.Text + '</option>');
});
$.ajaxSetup({ cache: false}); //If the SQL view changes, ensure that the user does not see old data.
});
在我的控制器中:
Dim ListItems As Generic.List(Of ClassName)
ListItems = (From x In c1 Select (New ClassName With {.Value = x.Value, .Text = x.Value})).ToList
我现在正在学习如何使用 PetaPoco 作为 ORM 来开发类似的应用程序。但是,我正在努力绑定数据库中的数据。
是否可以使用 PetaPoco 实现此目的?
我知道我需要先编写初始查询
var dataContext = new PetaPoco.Database("sqlserverce");
var Something = dataContext.Query<Models.Something.ClassName>("Query");
任何评论都会有很大的帮助
谢谢 詹姆斯.
因为我问这个问题已经有一段时间了,而且我已经解决了我的问题,所以我认为最好 post 这个问题并提供一个正式的答案。
感谢 ClearLogic 的帮助。
使用 .Fetch<> 解决了这个问题,我的最终查询看起来像这样
var x = dataContext.Fetch<ClassNameToRepresentListItems>("DefiningQuery");