Linq, Entity Framework and WCF - linq

If I have a customers and orders relationship in my Linq or EF model, at the WCF service layer I can add an order to the customer by calling
Customer.Orders.Add(customer);
When I access my customer object on the client, and want to add an order, there is no Add method, and the Orders propery is an array. Is there any way I can work with my client side object, they same way as I do on the server?

You are not supposed to be doing that, as the objects on the client have only a semantic similarity to the service's objects - they are not the same types.
This is done to conform to one of the important tenets of service-orientation: Services share schema and contract, but not class.
However, when you generate the client-side proxy, there are options where you can choose to have collections represented by List<T> instead of arrays.

Maybe you should look into What is .NET RIA Services?, .NET RIA Services.
This describes, and provides tools for those scenarios

Related

BreezeJS - Is there any way to use old style 'One controller to rule them all' with OData Web API?

I would like to expose the SQL Server Views via OData Web API but I don't want to create separate controllers for each views as there are too many of them and they will only accept GET verb for all the views.
I thought I can achieve this using BreezeController but it looks like I cannot as it is obsolete now (The package which has BreezeController attribute is marked as obsolete).
Is there any way to achieve this with OData Web API that works with BreezeJS?
The [BreezeController] attribute is not obsolete. In fact, it is central to the "happy path" Web API controllers you see in the Breeze samples. I wonder what lead you to think otherwise? What package are you using?
I'm referring to the ASP.NET Web API!
The ASP.NET Web API OData is a different matter. Despite "Web API" in the name, that is almost a completely different approach to server development with its own behaviors and wire format. It does not use the [BreezeController] attribute and never has.
I'm not sure what you meant by "view" in your phrase, "separate controllers for each view". I think you mean what I would call "type". For example, in OData you'd expect a "Product" endpoint for your Product entity type.
AFAIK, the Web API OData approach demands a separate controller per type. That's what Microsoft's Mike Wasson says in his tutorial. He writes ...
A controller is a class that handles HTTP requests. You create a separate controller for each entity set in your OData service.
BreezeJS supports Web API OData too ... although there are limitations imposed by the current Microsoft implementation that may give you pause.
We are working through these with the OData team and hope to have better news in the coming months.

Whether to use Models in MVC or models in MVVM?

I am creating an SPA (using visual studio 2013). The application gets data from the WCF service. The data generally involves C# collection. As the SPA is MVC based, I copy the data into Model objects and pass it to the view. Now, I am planning to use Knockout.js. Should I need to directly convert the data from WCF service into JSON or copy the data to Models (in MVC) and then convert them to JSON?
P.S:
My WCF service and the SPA lie on the same system. Currently I transfer the contents from the service to the web application using binary serialization and not in JSON format.
Probably the cleanest approach here is to simply return JSON from your controllers and not have MVC views (or WCF service) at all. This way you can keep the front end completely separate and the server code generally becomes a lot simpler.

MVC WebAPI with SPA

I am new to the WebAPI. I have 4 entities:
Location
Service
Item
Application
I have read several WebAPI tutorials. They all seem to have CRUD methods in each API Controller that deals with single entity. One functionality that I need is to simulate cascade dropdown and cascade update where Location determines range of Service. Each Service determines list of Service Item. Each Item may be used in a list of Application. The question is
Do I create 4 API Controllers with CRUD methods?
I need all 4 objects on one form as List Boxes that allow multi-selection.
Along side the 4 List Boxes, how to show a list of combination of selected value that are saved to a database table?
Which javascript library or framework is the best for SPA (Single Page App)? I am currently leaning towards Backbone.js and HotTowel.js.
Thank you.
You could expose your service as an OData service. If you wish to support filtering, then you should use the separate OData NuGet package, and develop your controllers. In this case four controllers would suit.
Then, you can use a client side rich data library such as breeze.js to make building requests to the OData service straightforward. You would then use an MV* client side framework to provide two way bindings between the client side view models and the UI elements.
Hot Towel isn't a JavaScript library, it's a Visual Studio extension which allows you to create a new project as a starting point for your SPA. The template requires Visual Studio 2012 and the ASP.NET Web Tools 2012.2 update.
It uses breeze.js, Knockout.js for the binding, and Durandal.js for navigation, life cycle, and view composition.

MVC3 - Is there a proper name for this type of service pattern?

I am using Controllers as services to return HTML/JSON. Is there a proper technical name for what I am doing here?
A user triggers an event
Perform AJAX GET
Request handled by Controller
Return HTML/JSON
Populate front end HTML object(s) with result
This strikes me as a service oriented design. It has the benefit of behaving like a RIA app. I have heard of "RESTFUL" services, but I don't know if this fits the bill.
I use the exact same schema in our main app. It's a subset of Service Oriented Design/Architecture. You actually use "services", such as: Login, CreateBlogPost, DeletePicture, Register, Connect and so on. But I believe that services serve broader goals. For example, exposing an API, which could be essentially accessed in the same manner you describe but respond to more HTTP verbs other than GET: POST, HEAD, PUT, DELETE. This is a RESTful service, as you mentioned.
So, to answer your question, the schema you describe plays a role in a good architected RIA. I don't believe it has a unique name of its own (besides being part of SOA).

Eager loading child properties using LINQ to CRM

Is there anyway I can eager load client defined child properties on a CRM entity using the LINQ to CRM Provider supplied in SDK 4.0.12? I'm looking for something the same as the pattern in Entity Framework as shown here. I'd love to be able to do this so we can align our repository interfaces with those we already have against EF.
As an aside, I know I can do it client side via a WCF Data Service exposing my DataContext and then use the .Expand() extension method. Therefore, it doesn't seem like such a stretch to allow me to perform the same at the server.

Resources