objective-c odatasdk - iphone

I am consuming OData WCF Data Service in my iPad application. I am able to add an object to the Entity at my server side but unable to add NSData field to the SQL Server image data field.
I am not getting any error while adding and saving the object at remote side.
can you help me how can I send NSData type value to SQL server image data type field using OdataSDK ?

I managed to upload a byte[] (NSData) file by using the ODataSDK for Objective-C by configuring my OData service to provide a Stream Service Provider. I started from a Visual Studio project that had my SQL Server tables mapped with the Entity Framework, so that OData already exposed the entities to save/read to.
It's important to note that the entity that has the file byte must have the m:hasStream attribute set in the Entity Framework .edmx file, which can be done only by manually editing the XML file (Have a look at this tutorial, which is made of three parts: here's the first )
Once you do so, the ODataSDK for ObjC provides the methods setSaveStream (and getReadStream) to save (and read) the NSData file (although I had some problems getting getReadStream to work, but it may be due to the fact that it was my first implementation of such service).
If you are uploading files larger than 64KB, have a look at this answer to properly configure your Web.config: https://stackoverflow.com/a/6907582/423816
Of course you also have to use the addObject: and saveChanges: methods, but this is what you'd do with any other OData entity.
Hope this helps

Related

Breeze JS : Entity Errors preventing patch-up on the client

I my client application I am calling entityManager.saveChanges to send all currently changed entities from the client up to the server. Then in the BeforeSaveEntity event on the server I am performing some server side validation on each entity to see if it should be excluded from the save map. So for example, my entity may have a value for description that is too long. So I return false from BeforeSaveEntity, and generate a new EntityError which will then be added to the saveResult.EntityErrors collection. All of the valid records that haven't been excluded from the save map then save off successfully, and my saveResult is returned to the client. But because of this single entity error, the auto-patchup of the entities returned does not occur back on the client. I looked at the source and basically there seems to be a check that says if there is anything in the saveResult.EntityErrors collection, don't bother with the patch-up. But There was only 1 entity that purposefully wasn't saved, so I still want to be able to patch up the others. Is this behavior by design? I want to be able to exclude certain entities from the save (which I can do using the BeforeSaveEntity event), but there doesn't seem to be any way of then getting the entity errors back to the client using the inbuilt mechanism, without the full patch-up being abandoned.
Saves in breeze are transactional if at all possible ( some backend providers, like MongoDb are not because they don't support it.). This means that if any failures are experienced with any entities within a save bundle the entire save is reverted and an error is returned to the client. This is by design.

One Entity Framework definition with two storage providers?

Setup
I have a SQL Server 2008 database that is accessed using the Entity Framework on the server.
Each client has a SQL Server Compact Edition 3.5 database for storing data when offline.
I use self tracking entities that are generated from the server defined Entity Framework.
Question
At the moment i have two EDMX defined, one for the server and another for the client, even though they are identical except for the storage provider. I use the self tracking entities from the server and they work fine with the client database. Is there a way to have just a single EDMX? At the moment there is a risk I will make a change to one EDMX and forget to make it to the other. Or am I using the wrong approach?
Note
I do not want to use the sync framework because of complex business logic that needs applying at the server side.
Unfortunately there is no direct way to use single EDMX with multiple storage providers. You must always have separate SSDL part for each provider. The common workaround is to export SSDL, MSL and CSDL as separate files (default setting adds them as resources to assembly) and use some script or pre-build action to create copy of SSDL file with all necessary changes for second provider (there can be also different data types between SQL Server and SQL Server CE). You will than use correct SSDL file per application by specifying it in connection string.
Another "better" solution is not using EDMX and use code first where this problem mostly doesn't exist - but that is architecture change.

Can't load related entities on the client using RIA Services

I am having trouble getting related entities to be loaded on the client using RIA Services and EF 4.1 with Silverlight.
I'm currently using the Include() method on my DbDomainService with an Expression parameter and am finding that when stepping through my service the related entities are loaded just fine. However, when the Queryable results are returned to the client NO related entities are loaded - they are null. All of my entities are marked with the [DataMember] attribute so I have assumed that it isn't a serialization issue. Moreover, my DbDomainService query method is marked with the [Query] attribute.
I was wondering if there is anything specific that has to be set up on the client when using RIA Services with EF 4.1 code first? I must be missing something, but I'm not sure what.
Any help would be appreciated.
Thanks,
sfx
While you may have used the .Include() in your service call, you also have to add the [Include] attribute in the metadata class that is also created.
The .Include() statement tells EF to generate the SQL necessary to retrieve the data, while the Include attribute tells WCF RIA Services to make sure the Entity Class is also created on the client.
Once the data arrives at the client, it needs to know what type of structure to put it in as well.
HTH

How to use Entity Framework 4.0 with Xml or in-memory Storage (non-SQL)

How do I specify Xml or just in-memory storge for Entity Framework models? The connection string requires a provider (usually a SQL provider string). But it won't let me omit the provider.
I realize I could completely throw away the designer generated objects and go pure POCO, but then I'd have to implement my own serialization layer (could do that, but it's overkill for the tiny project I'm working on).
Is there built-in support in EF 4.0 for this that I'm missing or do I just need to go the pure POCO route and discard the designer experience entirely :(
If you want to store data in Xml or memory you should probably not use EF. EF is designed to work with relational databases.
See also: Entity Framework with XML Files
For storing data in memory use System.Runtime.Caching
For storing data in xml files see: http://msdotnetsupport.blogspot.com/2007/04/reading-and-writing-xml-files-using-c.html
This is a good way to do what you're probably thinking.
Use a SQLite db as the backing store. That way you get you're single local file and you can still use almost all of EF.
http://dotnet.dzone.com/news/sqlite-entity-framework-4

Entity Framework connection metadata extraction

I am using the EntityFramework POCO adapter and since there are limitations to what microsoft gives access to with regards to the meta data, i am manually extracting the information i need out of the xml. The only problem is i want to get the ssdl, msl, csdl file names to load without having to directly check for the connection string node in app.config.
In short where in the ObjectContext/EntityConnection can i get access to these file names?
Worst case scenario i need to get the connection name from the EntityConnection object then load this from app.config and parse the string itself and extract the filenames myself. (But i obviously don't want to do that).
Thanks
I can think of two ways to use reflection here:
Dig into the EntityConnection. The connection string should be in there somewhere as a private variable.
The EDM metadata files are embedded in the assembly as resources by default. You should be able to reflect the assembly that contains the EDM and pull the files out directly. Use Reflector on your assembly that contains your EDM and you should see the embedded msl, ssdl, an csdl.
I think option 2 is more robust overall.
Have you looked at the ObjectContext.MetadataWorkspace? It's not the easiest library to work with, but I was able to get all of the information that I needed.
Julia Lerman has a good chapter on the subject in her EF book.