Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Entity Framework 101
Message
From
04/06/2014 11:04:12
 
 
To
04/06/2014 10:49:22
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
General information
Forum:
ASP.NET
Category:
Entity Framework
Environment versions
Environment:
C# 4.0
OS:
Windows 8
Network:
Windows 2000 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01601183
Message ID:
01601271
Views:
30
Maybe you're right :)

I started this project trying to develop an HTML5 offline application using jquery & javascript pulling data using my Mere Mortals .NET Business Objects and have now moved on to include ASP.NET MVC, knockout.js, entity Framework & Web API. So I think my problem at the moment is getting all these things to fit together.

I have watched a fair number of tutorials, but all are rather simplistic so when it comes down to me doing a real world application I realise what was missing from the tutorials.

>I would highly recommend watching some of the Pluralsight courses on MVC basics. From your messages, I feel you might be struggling with some of the core concepts. A half hour of training would go a long way.
>
>>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform