How to stream images (or any BLOB) in OData Service using Code First?
What I'm trying to accomplish is: Have a Client Entity, or a Product Entity streaming related images, and be able to upload/update images using an OData Service.
Using EF 4.1 and 'CODE FIRST' model Client side is a WPF app
So far I have a working service for the data-model, I can read, update my data, all good.
In order to enable image streaming, I followed Glenn Gailey BLog, "Streaming Photo OData Service Sample" over here: http://code.msdn.microsoft.com/Streaming-Photo-OData-7feb9239
Since the example uses an edmx file, I added a second service just for the images, with slight changes in order to link an image to a client / product in my data-model. So now the app loads the related images as stream form the second service. ( I can't get the "upload/add" a new image to work, but that's not to important right now).
In order to enable the streaming ability, and subsequently the Named-stream, one has to manually edit the .edmx file and add the property "hasStream=true". Then implement IDataServiceStreamProvider etc.
Long story, shorter question
I would like to be able to do is within my existing model, rather then having a second service with it's own model. How (and where) do I add this "hasStream" property in Code First???
Alterna开发者_如何学Gotively, Am I going overboard here and there is a way simpler procedure to work with images in OData?
PS: the images are rather small in size, mostly < 200KB with a few up to 1MBAppreciate any help, pointers, examples
Thanx
Andreas
No, I don't think it is possible. That HasStream
is custom structural annotation. It is not a feature of Entity framework but additional metadata read by WCF data services. Code first model doesn't support these custom annotations. Moreover WCF data services (except CTPs) don't support code first's context directly.
Edit:
I just did little research. There is an attribute System.Data.Services.Common.HasStreamAttribute
in System.Data.Services.Client
assembly. Try to mark your code first entity with this attribute. If you are using reflection provider it should hopefully work.
精彩评论