Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How can i get data from web service (asmx) using BreezeJs?
My asmx web service returns DTO objects which are not related with datacontext. How can I automaticaly, deliver metadata to breeze, without using Metadata() method from dbcontext?
I have already looked over the Edmunds sample, but in this sample, we have to manually write metadata for each entity. Can I avoid it using asmx web service and DTO objects?
Breeze currently accepts metadata in only two formats, a native json format and a csdl ( also converted to json) format ( used by Entity Framework backed models). Note that you can also deliver this metadata in combinations of these formats. i.e. via multiple importMetadata calls to the same metadataStore.
For your example you will need to create the metadata for each of your 'DTO' types, but this typically isn't that onerous. If you have a lot of them you could also write a simple app that uses reflection to build the metadata for you.
If you have a biggish model you don't have to write the metadata by hand. There is an easier way: use EF as a metadata design tool!
Take a look at the FoosMetadataProvider in the DocCode.DataAccess.EF of the DocCode sample (download it). It generates metadata for a Foo class that doesn't actually exist in any database at all! You could model your DTOs as if they mapped to a database with EF.
Using EF as a metadata design tool is a fast way to generate metadata on the server for models that are not actually using Entity Framework for data access. Just pretend that it is ... and then ignore the MetadataDbContext thereafter.
You don't have to carry EF in your production code either. You could use it in a separate project strictly for purposes of generating metadata. Pour that metadata into a script (there's an example of that in DocCode as well). Remember ... you're only using EF as a design time modeling tool. No one has to know; I promise I won't tell.
p.s.: EF is pretty good at this modeling business. You're not abusing it and I don't think it's a hack. You're not using the full framework ... and so what. You don't use all of jQuery either; that didn't stop you from serving it to your clients on every page, right?
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I'm creating an asp.net core 2.0 webapi project, using the default sample produced from 'dotnet new webapi'.
In the default GET method created for you I can see the Get method is happy to return a value type and an IEnumerable, but what return types are supported 'out of the box' to respond to the typical accept header types. I've searched, but I simply cannot find a thing.
e.g.
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
Searching I can can also see you can return an IActionResult for which you can use Ok and JSon methods to return data using the default accept header or directly as json.
But
Where do I find a definitive list of what can and cannot be sent
back?
Why is IEnumerable working (this is really me not knowing what is and isn't a valid return type)?
This is my typical frustrating story with ASP.Net, articles don't tell me answers properly, they are dated from 2013 and out of date and are no long valid, and I just keep going round in circles. I have no idea whether I'm reading about core 2, core 1, full dotnet, mvc 5, mvc 6, and they're all different. It's so much easier with Java :(
thanks.
The return type for all actions is IActionResult. That could be satisfied by any number of different things, whether actual *Result types (ViewResult, ContentResult, JsonResult, FileResult, etc.) or anything that can be converted into a *Result type. For example, returning a string typically results in a ContentResult, whereas returning an object will typically cause the serializer to kick off to return a JsonResult with the object serialized into JSON.
Long and short, you can pretty much return anything from an action. The framework is pretty smart about creating an appropriate result object from whatever you return. In situations where you know exactly what you want returned, you should return that. For example, if you always want JSON, then return Json(obj) rather than obj. However, if you want to be agnostic about it (return JSON or XML), then return the object directly, and let the framework pick the appropriate serializer.
Just an additional note regarding your confusion with what you're reading: there is only ASP.NET Core and ASP.NET MVC. MVC only goes up to major version 5. When you see MVC 6 referenced, it's actually ASP.NET Core, but back when it was still a very early pre-release. So many things changed on the way to 1.0, that anything that references MVC 6 should be considered completely useless at this point. Core 2.0 made a lot of major breaking changes to Core 1.0, so in general, anything you see reference Core 1.X at this point should be taken when a very large grain of salt. There may be useful information, but more likely than not, it's not accurate any more. Therefore, if you're looking for info on ASP.NET Core, look for 2.0. If it's any other lesser version, use it only if you can't find better info, and then, be prepared for things to not work quite as described. Again, avoid MVC 6 info altogether. Previous versions of MVC refer to the still available ASP.NET MVC, not Core, and won't be any help to you at all if you're trying to build a Core app.
Finally, full .NET or "the full framework", is mostly referenced in Core 1.X -themed articles and tutorials. At that time, .NET Core 1.X had a comparatively small API footprint, so usage of a lot of different libraries would require running on the full framework rather than Core (You could still build an ASP.NET Core web app - it just wouldn't actually target .NET Core). However, .NET Core 2.0 implements .NET Standard 2.0, which brings near complete API parity with the full framework (with the exception of mostly Windows-specific APIs). As a result, you can reference virtually any .NET library with .NET Core 2.0, now.
I am using Breeze JS and would like to implement a server with full CRUD functionality using Progress Openedge. The Breeze website talks a lot about being able to write your own server implementation but I can find no information describing the format of a save bundle that Breeze sends to the server. Does anyone know of any documentation or schema?
The documentation for this is buried in the DataServiceAdapters page. Look about halfway down, under the heading saveChanges (saveContext, saveBundle) -> promise.
There's an example of what the JSON looks like in this SO answer.
The SaveBundle is not documented for a very good reason: it has no definition in BreezeJS!
It could be any serialized object that your server requires to satisfy yoursaveChanges work flow. You can see that this is true by examining the a60_abstractDataServiceAdapter.js source in github:
proto._prepareSaveBundle = function (/*saveContext, saveBundle*/) {
...
throw new Error("Need a concrete implementation of _prepareSaveBundle");
};
Breeze does ship with an implementation b00_breeze.dataService.webApi that satisfies the expectations of the companion Breeze ASP.NET Web API helper classes such as ContextProvider. This implementation is worth studying if you decide to write your own server support code.
But it is only one of many possible implementations. An OData web server, for example, requires an entirely different package and format for "$batch" change-set saves. Only you know what's right for your "Progress Openedge" server.
All that said, we do delve into some critical aspects of the SaveBundle destined for Breeze Web API services in the documentation for "ContextProvider".
Feel free to follow-up with more specific questions after you've read that.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm iOS very fresh beginner..
I'm trying to build REST app that gets and updates data from/to some server (by http get and post requests using JSON data format).
I need to have some local saving mechanism (like Core Data) so that app can be used offline, but as soon as network is available it has to be synced (sent, refreshed) with server.
There will be lots of different requests on server, so there could be a lot of networking & json parsing code.
I would like to avoid having viewController classes overloaded with lots of json parsing code.
My question is - what is the best practice on iOS to accomplish this?
Should I have one apiCommunicator with all requests (using NSUrlConnection) (and use delegating ui-updates to viewController that has requested data)?
Or should I have api calls in different classes (one per one model class)?
What is standard approach?
Can you at least point me to some readings or sample projects where I can learn more about.
If possible, I would like to see/read some solution without using 3rd apis, since I'm already overloaded with lot's of new stuff within iOS itself :)
First of all consider MVC when developing for iOS (https://developer.apple.com/library/ios/documentation/General/Conceptual/DevPedia-CocoaCore/MVC.html).
My personal preference is having a model class which communicates with your API and reports the results via a delegate (or block or notification, depending on many factors (http://blog.shinetech.com/2011/06/14/delegation-notification-and-observation/)). This class could be singleton as your app will probably need to constantly talk with your server and you want a single always-alive object handling your requests.
So the overview would look like this:
Your views ask their controllers to do something (usually high level methods).
Your controller layer will translate your view requests and perform an appropriate task (one of which may be an API call).
Your controller will ask the model to perform an api method (say a GET).
It will receive the result upon completion from your model (maybe map the JSON results to an object) and then hand it down to views which may need to reflect something in the UI.
For your model class you can use NSUrlConnection for simple api calls. But as you said you will need JSON parsing (and maybe an object mapping). For that matter a framework like AFNetworking (https://github.com/AFNetworking/AFNetworking) would ease your life a lot (although you can do all that using classes in cocoa).
Just implement AFNetworking to your project and read the documentation. This would be helpful - https://github.com/AFNetworking/AFNetworking
Here is my knowing about ASP.NET SPA:
have to use Upshot to talk to the server;
have to use DbDataController to provide Web APIs;
have to use Entity Framework Code first...
so, many concerns come out:
have to provide metadata for the upshot to work, this will obviously expose the structure of your database;
can i use Entity Framework Database First instead of Code First? You may ask why. Because Code First don't provide you the ability to customize your database(index customization, stored procedure...etc.);
A problem i met: when i add a "TestUpshot.edmx" file(generated from database 'northwind') to the MySpaApp.Models folder(trying to test whether i can use the edmx classes in the MyDbDataController class, and generate proper metadata in the client side), and run the application, there is an exception:"System.ArgumentException: Could not find the conceptual model type for MySpaApp.Models.Categories."...
Need help here, thanks in advance.
Dean
I may be missing something, but there is no requirement to use any of the technologies you've listed.
An SPA is just a pattern. You can use whatever you need to achieve that. There may be benefits with choosing certain technologies, ie templates, tutorials, etc.
Doesn't really answer your question, but should lead you to experiment with what you've got.
SPA is actually a way to conceptualize your client application. SPA comes the closest to the fat client - data server concept from the current web approaches. Definitely this will be the ruling concept within a couple of years.
Your concerns can be addressed using JayData at http://jaydata.codeplex.com that provides advanced, high level data access for JavaScript against any kind of EntityFramework back-ends (db, model or code first). Check out this video that presents the whole cycle from importing your EDMX from SQL (this could eighter be model first definition as well) to inserting a new product item in the Products table from JavaScript.
In order to avoid magic strings when running the ExecuteStore command is it possible to get underlying table name [and columns] from the model in Entity Framework 4
Liam
I can't tell you if there is, but the best shot would be to dive into the metadata of the context.
This might help you, it is a documentation about the metadata of the EF. If you can't find it in the metadata, you are most likely out of luck.
Edit according to this (bottom of the page):
I have also been trying to query the mapping metadata. I wanted to find the metadata which describes how tables and entities are mapped and which stored procedures are mapped to entities. I was not able to find the metadata I needed via the MetadataWorkSpace. Afterwards Danny Simmons from Microsoft did let me know that this mapping metadata is not available publically and that it is something they have to do in a future release of the Entity Framework.
It seems to be impossible at the moment as this information is not publically avaiable; however, this is from 2008, so it might have changed in the meantime.
I'll quote Rowan Miller ...
Hi,
Unfortunately in CT4 there is no
public surface that allows you to find
what the table name is for a given
entity type. This is actually a
limitation of EF in general as we
don't have a public API to access the
mapping section of the model. This is
something we are working to improve at
the moment.
~Rowan
CTP 4 being a pre-production update to EF4, in this case. My only suggestion for bypassing this, evil as it is, is for you to try parsing the XML in the model directly, and strip the table names from that. Very evil, but it should be doable. Remember though that models can relate to multiple tables, or views, or combinations.