Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Entity Framework 101
Message
De
04/06/2014 09:42:24
 
 
À
03/06/2014 12:33:10
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Entity Framework
Versions des environnements
Environment:
C# 4.0
OS:
Windows 8
Network:
Windows 2000 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01601183
Message ID:
01601261
Vues:
32
Thanks Mike,

is it possible to then sort the Products?

In my real life case I am pulling back a list of Routes and displaying this list in a drop down list. Currently the list is unordered and I want to sort it alphabetically.

this is the code in my Route.cshtml:
@model IBCPackageTracking.Route

@{
    ViewBag.Title = "Route";
}

<h2>Get Run Sheet for your Route</h2>
<div class="content">
    <div class="float-left">
        <select id="SelectRoute" data-bind="options: routes, optionsText: 'rte_name', optionsCaption: 'Select a Route', optionsValue: 'rte_pk'">
        </select>
        <p>Date: <input type="text" id="datepicker"></p>
        <div><input type="submit" value="Get Run Sheet" /></div>
    </div>

</div>
@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">

<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
    $(function () {
        $("#datepicker").datepicker();
    });
</script>

    <script type="text/javascript" src="@Url.Content("~/Scripts/knockout-2.2.0.js")"></script>
    <script type="text/javascript">
        // View-model will go here
        function RoutesViewModel() {
            var self = this;
            self.routes = ko.observableArray();

            var baseUri = '@ViewBag.ApiUrl';

            self.create = function (formElement) {
                // If the form data is valid, post the serialized form data to the web API.
                $(formElement).validate();
                if ($(formElement).valid()) {
                    $.post(baseUri, $(formElement).serialize(), null, "json")
                        .done(function (o) {
                            // Add the new product to the view-model.
                            self.routes.push(o);
                        });
                }
            }

            self.update = function (route) {
                $.ajax({ type: "PUT", url: baseUri + '/' + route.Id, data: route });
            }

            self.remove = function (route) {
                // First remove from the server, then from the view-model.
                $.ajax({ type: "DELETE", url: baseUri + '/' + route.Id })
                    .done(function () { self.products.remove(route); });
            }

            $.getJSON(baseUri, self.routes);
        }

        $(document).ready(function () {
            ko.applyBindings(new RoutesViewModel());
        })
    </script>
>
>db.Products.AsEnumerable();
>
>
>The query executes when you actually enumerate the results, so in that instance AsEnumerable() actually kicks off the query. See LINQ's Deferred Execution feature for more reference. It also makes it possible to do something like this:
>
>
>   var query = db.Products.AsQueryable(); //this does not execute the query
>
>   if (productNameFilter != null
>   {
>      query = query.Where(p => p.ProductName == productNameFilter); //Still does not execute...
>   }
>
>   return query.ToArray(); //The ToArray() kicks off the execution, because it takes it out of IQueryable data type.
>
>
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform