在以前的项目中,我使用LINQ查询数据库表,然后将结果绑定到MVC应用程序的下拉列表中。
例如在我看来:
<button>Add Div</button>
<div id="parent">
</div>
在我的控制器中:
$.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.
});
我现在正在学习如何使用PetaPoco作为ORM开发类似的应用程序。但是我正在努力绑定数据库中的数据。
是否可以使用PetaPoco实现这一目标?
据我所知,我需要先写初始查询
Dim ListItems As Generic.List(Of ClassName)
ListItems = (From x In c1 Select (New ClassName With {.Value = x.Value, .Text = x.Value})).ToList
任何评论都会有很大的帮助
由于 詹姆斯。
答案 0 :(得分:1)
由于我问过这个问题已经有一段时间了,而且我已经解决了我的问题,我认为最好发布这个并提供正式答案。
感谢ClearLogic的帮助。
使用.Fetch&lt;&gt;解决了这个问题,我的最终查询最终看起来像这样
var x = dataContext.Fetch<ClassNameToRepresentListItems>("DefiningQuery");