Adding new entity to database via web api OData service keeps giving me the following error.
"Cannot convert a primitive value to the expected type 'Edm.DateTime'. See the inner exception for more details." I googled a bit and found out that it's related to OData not supporting DateTime type. I am using EF with database first approach and some of the entities have properties which are of DateTime Type.
Any suggestion for the issue?
Thanks.
Nyi
Related
I have tried to make custom mapping between my DTO and Entity.
I have tried to use [AutoMapfrom(typeof)..] function to mapping.
I have tried to use ObjectMapper.Map function in my application layer for my service.
I'm Using Asp.Net boilerplate framework to create a wep api.
Even though I tried everything that I have written on the top, I still get Missing type map configuration or unsupported mapping. Error when I run my get method which is about my app. I will be glad if someone can help me.
I wrote several plugin for previous CRM versions, most of them using Early Bound entities.
Right now I am writing a plugin for version 2015 with just one custom entity; the plugin contains the generated entity definition (early-bound entity class).
As soon as I attempt to retrieve an entity using the Organization Service in the Plugin Pipeline I get the following exception:
Element 'http://schemas.microsoft.com/xrm/2011/Contracts:Entity' contains data from a type that maps to the name 'http://schemas.microsoft.com/xrm/2011/Contracts:new_TestEntity'. The deserializer has no knowledge of any type that maps to this name. Consider changing the implementation of the ResolveName method on your DataContractResolver to return a non-null value for name 'new_TestEntity' and namespace 'http://schemas.microsoft.com/xrm/2011/Contracts'.
Plugin has a ProxyTypesAssembly attribute.
I am attempting to intercept the RetrieveMultiple and Retrieve messages. It's all working. It faults as soon as I attempt to execute a Retrieve within the plugin execution context (using the pipeline's org service).
Looks like you have changed your entity model without regenerating the early bound classes. Try regenerating your early bound entities.
Looks like the same issue as described in CRM 2015 SDK : The deserializer has no knowledge of any type that maps to this name
I have a lighweight setup where I am using Web API 2 with OData but do not create an "/odata" endpoint with its accompanying "/odata/$metadata" but instead just use standard ApiController's with attribute routing and Get methods marked with an override of [Queryable]: [InlineCountQueryable] detailed here Web API, OData, $inlinecount and testing.
It all works very well except that I can only expose dedicated model classes without any collections or object properties because the JSON serializer serializes the whole object graph. My ideal behavior would be to just have all collections ignored completely and object properties only included on $expand.
I believe this can be made to work because an OData Web Api 2 scaffold VS 2013 creates over an entity framework context has similar behavior, but I would like to keep this as lean as possible and avoid going that route as I found it to be a bit brittle and this service does not need to expose a $metadata description.
Update
I did some digging in the aspnet samples and found the "CustomODataFormatter" sample which seems to expose the machinery I would need to modify.. however the ODataSerializerProvider/ODataSerializer setup outlined there does not work with with attribute routing at all (any method defined with [Route("Some/Url")]).
Given that this seems to be what I need, does anyone know if attribute routing and the odata serializer provider mechanism should work together?
[JsonIgnore] or [DataMember] can be used to ignore properties for json.net serializer. webapi.odata 5.2 supports ODataRouteAttribute, an example is here.
I created a WebAPI2 OData provider following Mike Wasson's tutorial found here. I then created a F# project to use the type providers to consume the service following the tutorial found here. The problem is that I am getting this exception when creating the Type Provider:
Error 1 The type provider 'Microsoft.FSharp.Data.TypeProviders.DesignTime.DataProviders' reported an error: error 7001: The element 'DataService' has an attribute 'DataServiceVersion' with an unrecognized version '3.0'.
Apparently, the most recent F# type providers do not support OData version 3. Is there a way that I can alter my OData service to return OData2 so that I can use the current F# type providers? Ideally, the F# type providers will support OData3 soon...
What are you using to host the OData service - WebAPI or WCF Data Services? If the former, there doesn't seem to be much support to gracefully fall back to V2. With WCF Data Services you can change the MaxVersion (the template DataService has the code in it) to V2 - I -believe- that this should do the trick.
I’m thinking of using OData for my web service (based on Web API). Unfortunately, my datasource is NOT IQueryable. Instead of implementing my own IQueryable I pretty much followed this blog post.
What I don’t understand is how to get to my entity data model (EDM)? Do I have to model an EDM for example in the Designer? Or is this for EF only and I can use „plain“ classes instead and set relation-attributes? I don’t want to expose my internal data structures therefore my EDM is more like DTOs...
In an example I’ve seen that I‘m supposed to derive from EntitySetController in order to get the OData-compliant HTTP response. I believe I can’t use EntitySetController as I don’t support IQueryable. What am I supposed to do in order to get a proper response anyway?
You can build an EDM model yourself. You can use the ODataConventionModelBuilder class to build your EDM model. This tutorial has some sample code.
Also, checkout the samples on OData from here, especially the ODataServiceSample and ODataCompositeKeySample. They should get you started.
Also, if you do not have an IQueryable, you could derive from ODataController instead of EntitySetController.