Olingo V2 - Referential Constraint check on entities' properties - spring-data-jpa

I am using Olingo 2.0.11 on top of Hibernate. I've built relationship between entities and the navigation property works fine by define the #OneToOne annotation to entities' properties:
public class MetaClass {
#OneToOne(mappedBy = "metaClassEntity", cascade = {CascadeType.MERGE, CascadeType.REFRESH}, optional = false)
private MetaClassReport metaClassReport;
}
public class MetaClassReport {
#OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER, targetEntity = MetaClass.class)
#JoinColumns({
#JoinColumn(name = "meta_class", referencedColumnName = "id", insertable = false, updatable = false),
#JoinColumn(name = "tenant_id", referencedColumnName = "tenant_id", insertable = false, updatable = false)})
private MetaClass metaClassEntity;
}
and the Edm looks like (notice the navigation property):
<EntityType Name="MetaClassReport">
<Key>
<PropertyRef Name="Id"></PropertyRef>
<PropertyRef Name="TenantId"></PropertyRef>
</Key>
<Property Name="AppCode" Type="Edm.String" Nullable="true" MaxLength="50"></Property>
<Property Name="CreateTime" Type="Edm.DateTime" Nullable="false"></Property>
<Property Name="Creator" Type="Edm.String" Nullable="false" MaxLength="36"></Property>
<Property Name="DataRelation" Type="Edm.String" Nullable="true" MaxLength="20"></Property>
<Property Name="Id" Type="Edm.String" Nullable="false" MaxLength="22"></Property>
<Property Name="JoinGeneral" Type="Edm.String" Nullable="true" MaxLength="255"></Property>
<Property Name="Links" Type="Edm.String" Nullable="true" MaxLength="255"></Property>
<Property Name="MainEntity" Type="Edm.String" Nullable="true" MaxLength="22"></Property>
<Property Name="MetaClass" Type="Edm.String" Nullable="false" MaxLength="22"></Property>
<Property Name="MicroServiceCode" Type="Edm.String" Nullable="true" MaxLength="50"></Property>
<Property Name="Modifier" Type="Edm.String" Nullable="true" MaxLength="36"></Property>
<Property Name="ModifyTime" Type="Edm.DateTime" Nullable="true"></Property>
<Property Name="QuerySchema" Type="Edm.String" Nullable="true" MaxLength="22"></Property>
<Property Name="Version" Type="Edm.Int32" Nullable="false"></Property>
<Property Name="TenantId" Type="Edm.String" Nullable="false" MaxLength="36"></Property>
<NavigationProperty Name="MetaClassDetails" Relationship="default.MetaClass_MetaClassReport_One_One0" FromRole="MetaClassReport" ToRole="MetaClass"></NavigationProperty>
</EntityType>
<Association Name="MetaClass_MetaClassReport_One_One0">
<End Type="default.MetaClass" Multiplicity="1" Role="MetaClass"></End>
<End Type="default.MetaClassReport" Multiplicity="0..1" Role="MetaClassReport"></End>
<ReferentialConstraint>
<Principal Role="MetaClass">
<PropertyRef Name="Id"></PropertyRef>
<PropertyRef Name="TenantId"></PropertyRef>
</Principal>
<Dependent Role="MetaClassReport">
<PropertyRef Name="MetaClass"></PropertyRef>
<PropertyRef Name="TenantId"></PropertyRef>
</Dependent>
</ReferentialConstraint>
</Association>
Now I have the requirement to do the referential check when update MetaClassReport associated to a MetaClass by:
localhost:8080/odata/MetaClassReports
and the body is:
{
"Id": "7s",
"YtenantId": "1qaz2wsx",
"Links": "",
"Version": 1,
"CreateTime": "2022-12-31T18:59:59",
"Creator": "chenhem",
"MetaClassDetails": {
"Id": "5s",
"YtenantId": "1qaz2wsx",
"LegacyId": "12121212",
"TableName": "classTable",
"TableType": 0,
"Uri": "aa.bb.testmetaclass",
"Name": "testmetaclass",
"MetaComponentId": "11111111111",
"Version": 1,
"CreateTime": "2022-12-31T18:59:59",
"Creator": "chenhem"
}
}
then I notice that Olingo would not check the reference constraint between MetaClass and MetaClass report, the MetaClass will be inserted into DB no matter the "MetaClass":"1s" exists in MetaClass table or not.
I am wondering if the <ReferentialConstraint> in Edm is just an illustration, or indeed it will do some effects just because I missed some configuration or implementation?
If the <ReferentialConstraint> is just a metadata illustration, then how should I implement such a key reference value check? (DB foreign key is not an option for me), thanks in advance.

Related

Passing Odata object to create an entity set

I am trying to call a Odata service (crequestSet) which will create an article in MDG system.
I need to pass few parameters from the ui5 input fields and some should be hard coded values.
I have created a request.json file under models folder:
{
"CR_MARA": {
"Matk": "",
"Mtart": "HAWA",
"Attyp": "01",
"Meins": "EA"
},
"CR_MAW1": {
"Wladg": "0001",
"Wbkla": "3100"
},
"CR_MARM": {
"Meinh": "EA",
"Umrez": "1",
"Umren": "1"
},
"CR_MAKT": {
"Spras": "EN",
"Maktg": "Art 101 A",
"Maktx": "Art 101 A"
},
"CR_STEU": {
"Aland": "DE",
"Tatyp": "TTX1",
"Taxkm": "0"
}
}
Now i am trying to call the service /createrequest by using the model.
Create ('EnitityEset',oData {Success:"",Failure:""}) of the odata model in sapui5.
For a simple JSON model like:
{
"store": "",
"merchCat": "",
}
i can simple do:
var oData = {
Store: oLocal.getProperty("/store"),
MerchCat: oLocal.getProperty("/merchCat")
}
and then call the create method:
oModel.create("/crequestSet", oData, {
success: this._fnSuccess.bind(this),
error: this._fnFailed.bind(this)
})
But how do i pass the complex json object:
{
"CR_MARA": {
"Matk": "",
"Mtart": "HAWA",
"Attyp": "01",
"Meins": "EA"
},
"CR_MAW1": {
"Wladg": "0001",
"Wbkla": "3100"
},}
to the oModel.Create ?
I tried to do var oData = JSONModel.Stringyfy() to convert into a string,but it's not working and giving a error while service call.
The metadata structure of the crequest service:
-<EntityType sap:content-version="1" Name="crequest">
-<Key>
<PropertyRef Name="Matnr"/>
</Key>
<Property Name="ReasonForRequest" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:unicode="false" MaxLength="60" Nullable="false" Type="Edm.String"/>
<Property Name="Matnr" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:unicode="false" MaxLength="40" Nullable="false" Type="Edm.String" sap:label="Material"/>
<Property Name="CrDescription" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:unicode="false" MaxLength="60" Nullable="false" Type="Edm.String"/>
<Property Name="CrequestType" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:unicode="false" MaxLength="8" Nullable="false" Type="Edm.String"/>
<Property Name="CrequestId" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:unicode="false" MaxLength="12" Nullable="false" Type="Edm.String"/>
<Property Name="Matkl" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:unicode="false" MaxLength="9" Nullable="false" Type="Edm.String"/>
<Property Name="RefMatnr" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:unicode="false" MaxLength="40" Nullable="false" Type="Edm.String" sap:label="Material"/>
<Property Name="Reason" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:unicode="false" MaxLength="2" Nullable="false" Type="Edm.String"/>
<Property Name="Message" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:unicode="false" MaxLength="220" Nullable="false" Type="Edm.String" sap:label="Message Text"/>
<NavigationProperty Name="CR_ATTACHMASTER" ToRole="ToRole_CR_ATTACHMASTER" FromRole="FromRole_CR_ATTACHMASTER" Relationship="UGIOD02_RFM_SRV.CR_ATTACHMASTER"/>
<NavigationProperty Name="CR_UOM" ToRole="ToRole_CR_UOM" FromRole="FromRole_CR_UOM" Relationship="UGIOD02_RFM_SRV.CR_UOM"/>
<NavigationProperty Name="CR_MARA" ToRole="ToRole_CR_MARA" FromRole="FromRole_CR_MARA" Relationship="UGIOD02_RFM_SRV.CR_MARA"/>
<NavigationProperty Name="CR_MARC" ToRole="ToRole_CR_MARC" FromRole="FromRole_CR_MARC" Relationship="UGIOD02_RFM_SRV.CR_MARC"/>
<NavigationProperty Name="CR_MAKT" ToRole="ToRole_CR_MAKT" FromRole="FromRole_CR_MAKT" Relationship="UGIOD02_RFM_SRV.CR_MAKT"/>
<NavigationProperty Name="CR_MARD" ToRole="ToRole_CR_MARD" FromRole="FromRole_CR_MARD" Relationship="UGIOD02_RFM_SRV.CR_MARD"/>
<NavigationProperty Name="CR_MARM" ToRole="ToRole_CR_MARM" FromRole="FromRole_CR_MARM" Relationship="UGIOD02_RFM_SRV.CR_MARM"/>
<NavigationProperty Name="CR_MVKE" ToRole="ToRole_CR_MVKE" FromRole="FromRole_CR_MVKE" Relationship="UGIOD02_RFM_SRV.CR_MVKE"/>
<NavigationProperty Name="CR_MAW1" ToRole="ToRole_CR_MAW1" FromRole="FromRole_CR_MAW1" Relationship="UGIOD02_RFM_SRV.CR_MAW1"/>
<NavigationProperty Name="CR_STEU" ToRole="ToRole_CR_STEU" FromRole="FromRole_CR_STEU" Relationship="UGIOD02_RFM_SRV.CR_STEU"/>
<NavigationProperty Name="CR_SAUSPW" ToRole="ToRole_CR_SAUSPW" FromRole="FromRole_CR_SAUSPW" Relationship="UGIOD02_RFM_SRV.CR_SAUSPW"/>
<NavigationProperty Name="CR_SVARKY" ToRole="ToRole_CR_SVARKY" FromRole="FromRole_CR_SVARKY" Relationship="UGIOD02_RFM_SRV.CR_SVARKY"/>
<NavigationProperty Name="CR_PURCHINFO" ToRole="ToRole_CR_PURCHINFO" FromRole="FromRole_CR_PURCHINFO" Relationship="UGIOD02_RFM_SRV.CR_PURCHINFO"/>
<NavigationProperty Name="CR_WLK2" ToRole="ToRole_CR_WLK2" FromRole="FromRole_CR_WLK2" Relationship="UGIOD02_RFM_SRV.CR_WLK2"/>
<NavigationProperty Name="CR_BOM" ToRole="ToRole_CR_BOM" FromRole="FromRole_CR_BOM" Relationship="UGIOD02_RFM_SRV.CR_BOM"/>
<NavigationProperty Name="CR_MBEW" ToRole="ToRole_CR_MBEW" FromRole="FromRole_CR_MBEW" Relationship="UGIOD02_RFM_SRV.CR_MBEW"/>
<NavigationProperty Name="CR_CHARACP" ToRole="ToRole_CR_CHARACP" FromRole="FromRole_CR_CHARACP" Relationship="UGIOD02_RFM_SRV.CR_CHARACP"/>
<NavigationProperty Name="CR_MAMT" ToRole="ToRole_CR_MAMT" FromRole="FromRole_CR_MAMT" Relationship="UGIOD02_RFM_SRV.CR_MAMT"/>
<NavigationProperty Name="CR_CLASSGEN" ToRole="ToRole_cr_classgen" FromRole="FromRole_cr_classgen" Relationship="UGIOD02_RFM_SRV.cr_classgen"/>
<NavigationProperty Name="CR_MESSAGE" ToRole="ToRole_Messages" FromRole="FromRole_Messages" Relationship="UGIOD02_RFM_SRV.Messages"/>
<NavigationProperty Name="CR_CLASSASGN" ToRole="ToRole_Classasgen_As" FromRole="FromRole_Classasgen_As" Relationship="UGIOD02_RFM_SRV.Classasgen_As"/>
<NavigationProperty Name="CR_VALUATION" ToRole="ToRole_Valuation_As" FromRole="FromRole_Valuation_As" Relationship="UGIOD02_RFM_SRV.Valuation_As"/>
<NavigationProperty Name="CR_SEASON" ToRole="ToRole_Season_det" FromRole="FromRole_Season_det" Relationship="UGIOD02_RFM_SRV.Season_det"/>
</EntityType>
sap.ui.model.odata.v2.ODataModel, method created accepts three parameters, being the second (oDatain the API Reference) the deep object you need to pass.
var oData = {
ReasonForRequest: "X",
Matnr: "Y",
RefMatnr: "Z",
CR_MARA: {
Matk: "",
Mtart: "HAWA",
Attyp: "01",
Meins: "EA"
},
CR_MAW1: [
{
Wladg: "0001",
Wbkla: "3100"
}
]
}
oModel.create("/EntitySet", oData, { } );
Please note some important concepts:
CR_MARA and CR_MAW1 are your NavigationProperties in the metadata.
As you did only provice your service metadata partially, it's not
possible to know what are the properties for each entity. The
associations in your metadata (not available in the metadata)
contain information about cardinalitty.
So if CR_MARA has
cardinalitty 1..1 it should be a deep object inside oData whilst
CR_MAW1 has cardinalitty 1..* it should be a array of objects
inside oData.
Moreover, it's semantically wrong to name EntitySets with "operation specific" names, like "CreateEntitySet" or "DeleteEntitySet" as you can (and tipically will) implement many operations in the same entity like Query, Read and Create at the same time.
The oData model (I assume you use v2) takes care of the structure when you use oModel.createEntry() or oModel.create(). You can just put the whole object into the second properties argument. I forked a northwind example project northwind-sapui5 to create a working example.

SAPUI5 - Change the Column Name and Properties from smarttable from oData with no Annotation

I'm developing a SAPUI5 application that's use a smart table component. But the oData provided does not send any annotations in the metatdata file. I'm starting selecting these fields from oData: PriorityName,OrderTypeType,OrderTypeName,Id,DateOpen,HourOpen,BrandName,EquipmentId,EquipmentNumber,SymptomName. But i want to show their as Priority Name, Order Type, Order Type Name, Id, Date Open, Hour Open, Brand Name, Equipment Id, Equipment Number and Symptom Name, respective, in table column header and p13ndialog.
I know that is changed by default in the sap:label property in Property Name tag under EntityType. But according the oData developer, they cant send it to me (He was using JPA and oLingo).
The code above is for my smarttable and the entity used in metadada.
<smartTable:SmartTable entitySet="CustomerOrders" id="tbOrders" tableType="Table" useExportToExcel="true" beforeExport="onBeforeExport"
header="Ordens de Manutenção" showRowCount="true" enableAutoBinding="true" beforeRebindTable="onBeforeRebindTable"
initiallyVisibleFields="PriorityName,OrderTypeType,OrderTypeName,Id,DateOpen,HourOpen,BrandName,EquipmentId,EquipmentNumber,SymptomName"
class="sapUiResponsiveContentPadding">
<smartTable:customToolbar>
<OverflowToolbar design="Transparent">
<ToolbarSpacer/>
<OverflowToolbarButton icon="sap-icon://sort" text="Sort" press="onSort"/>
<OverflowToolbarButton icon="sap-icon://filter" text="Filter" press="onFilter"/>
</OverflowToolbar>
</smartTable:customToolbar>
<table:Table id="innerUi5Table" growing="true" selectionMode="None" visibleRowCountMode="Auto">
<table:rowSettingsTemplate>
<table:RowSettings highlight="{ path: 'PriorityName', formatter: '.formatter.OrderStatusFormatter' }"/>
</table:rowSettingsTemplate>
</table:Table>
</smartTable:SmartTable>
Metadata
<EntityType Name="CustomerOrder">
<Key>
<PropertyRef Name="Id"/>
</Key>
<Property Name="BrandName" Type="Edm.String" Nullable="true" MaxLength="150"/>
<Property Name="City" Type="Edm.String" Nullable="true" MaxLength="45"/>
<Property Name="ContactFirstname" Type="Edm.String" Nullable="true" MaxLength="45"/>
<Property Name="ContactLastname" Type="Edm.String" Nullable="true" MaxLength="45"/>
<Property Name="Country" Type="Edm.String" Nullable="true" MaxLength="2"/>
<Property Name="CustomerId" Type="Edm.Int64" Nullable="true"/>
<Property Name="DateOpen" Type="Edm.DateTime" Nullable="true"/>
<Property Name="EquipmentId" Type="Edm.String" Nullable="true" MaxLength="10"/>
<Property Name="EquipmentNumber" Type="Edm.String" Nullable="true" MaxLength="12"/>
<Property Name="EquipmentType" Type="Edm.String" Nullable="true" MaxLength="40"/>
<Property Name="FantasyName" Type="Edm.String" Nullable="true" MaxLength="45"/>
<Property Name="HourOpen" Type="Edm.Time" Nullable="true"/>
<Property Name="Id" Type="Edm.Int64" Nullable="false"/>
<Property Name="Latitude" Type="Edm.String" Nullable="true" MaxLength="12"/>
<Property Name="Longitude" Type="Edm.String" Nullable="true" MaxLength="12"/>
<Property Name="ManufacturerSerialNumber" Type="Edm.String" Nullable="true" MaxLength="255"/>
<Property Name="Material" Type="Edm.String" Nullable="true" MaxLength="8"/>
<Property Name="Neighborhood" Type="Edm.String" Nullable="true" MaxLength="45"/>
<Property Name="Note" Type="Edm.String" Nullable="true" MaxLength="10"/>
<Property Name="Obs" Type="Edm.String" Nullable="true" MaxLength="150"/>
<Property Name="OrderTypeId" Type="Edm.String" Nullable="true" MaxLength="4"/>
<Property Name="OrderTypeName" Type="Edm.String" Nullable="true" MaxLength="45"/>
<Property Name="OrderTypeType" Type="Edm.String" Nullable="true" MaxLength="45"/>
<Property Name="OsImbera" Type="Edm.String" Nullable="true" MaxLength="8"/>
<Property Name="Phone" Type="Edm.String" Nullable="true" MaxLength="11"/>
<Property Name="Plant" Type="Edm.String" Nullable="true" MaxLength="4"/>
<Property Name="PriorityId" Type="Edm.Int32" Nullable="true"/>
<Property Name="PriorityName" Type="Edm.String" Nullable="true" MaxLength="15"/>
<Property Name="State" Type="Edm.String" Nullable="true" MaxLength="2"/>
<Property Name="Status" Type="Edm.String" Nullable="true" MaxLength="1"/>
<Property Name="Street" Type="Edm.String" Nullable="true" MaxLength="150"/>
<Property Name="SymptomId" Type="Edm.Int64" Nullable="true"/>
<Property Name="SymptomName" Type="Edm.String" Nullable="true" MaxLength="45"/>
<Property Name="SymptomObjTecnico" Type="Edm.String" Nullable="true" MaxLength="10"/>
<Property Name="SymptomSAP" Type="Edm.String" Nullable="true" MaxLength="8"/>
<Property Name="TechnicalObjName" Type="Edm.String" Nullable="true" MaxLength="255"/>
<Property Name="WarrantyObs" Type="Edm.String" Nullable="true" MaxLength="45"/>
<Property Name="WorkCenter" Type="Edm.String" Nullable="true" MaxLength="8"/>
<Property Name="Zipcode" Type="Edm.String" Nullable="true" MaxLength="9"/>
</EntityType>
Redefine the rows/columns in your XML manually and bind your labels against i18n model, where you can define all the needed labels.
The bad thing about it - you cannot influence on the columns that potentially could be added via personalisation. Possible workaround - redefine ALL the columns. But in this case once the backend get changed, you have to adjust UI accordingly.

SAPUI5 - mockup server

I'm following this Mockup Server tutorial for SAPUI5. But I'm not able to retrieve the data and set it to my model. Here's what I do:
I have slightly changed the data so, so two things have to be changed:
json data - Person.json:
{ "id":1,
"first_name":"Chris",
"last_name":"Johnston", "email":"cjohnston0#dailymotion.com", "gender":"Male", "ip_address":"119.220.205.173" }
emphasized text
``
<edmx:Edmx Version="1.0"
xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"/>
<edmx:DataServices m:DataServiceVersion="1.0"
m:MaxDataServiceVersion="3.0">
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<Schema Namespace="PersonsData" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
<EntityType Name="Person">
<Key>
<PropertyRef Name="id"/>
</Key>
<Property name="id" Type="Edm.Int16" Nullable="false" />
<Property Name="first_name" Type="Edm.String" Nullable="false" MaxLength="40" FixedLength="false" Unicode="true"/>
<Property Name="last_name" Type="Edm.String" Nullable="false" MaxLength="40" FixedLength="false" Unicode="true"/>
<Property Name="email" Type="Edm.String" Nullable="false"/>
<Property Name="gender" Type="Edm.String" Nullable="false" MaxLength="40" FixedLength="false"/>
<Property Name="ip_address" Type="Edm.String" Nullable="false" MaxLength="40" FixedLength="false" Unicode="true"/>
</EntityType>
</Schema>
<Schema Namespace="databinding.PersonsData.Model" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
<EntityContainer Name="PersonEntities" m:IsDefaultEntityContainer="true" p6:LazyLoadingEnabled="true"
xmlns:p6="http://schemas.microsoft.com/ado/2009/02/edm/annotation">
<EntitySet Name="Persons" EntityType="PersonsData.Invoice"/>
</EntityContainer>
</Schema>
</edmx:DataServices>
The SAPUI5 Web IDE says that edmx namespace does not exist.
So I went to check edmx namespace and it does not exists.
Chrome developer tools reports the same error:
Could this be the problem?
I checked and mockserver.init() is triggered.
Did Microsoft moved this namespace somewhere? Cause I was not able to find it.
Thanks
what I see is that you messed up your XML structure. As the error says your XML is invalid.
You've closed the surrounding edmx:Edmx tag at the beginning of the document
You've closed the edmx:DataServices tag too early
Furthermore the attribute name of the property id is in lowercase. Try to make an uppercased Name.
Try to use this xml:
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
<edmx:DataServices m:DataServiceVersion="1.0" m:MaxDataServiceVersion="3.0"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<Schema Namespace="PersonsData" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
<EntityType Name="Person">
<Key>
<PropertyRef Name="id"/>
</Key>
<Property Name="id" Type="Edm.Int16" Nullable="false"/>
<Property Name="first_name" Type="Edm.String" Nullable="false" MaxLength="40" FixedLength="false" Unicode="true"/>
<Property Name="last_name" Type="Edm.String" Nullable="false" MaxLength="40" FixedLength="false" Unicode="true"/>
<Property Name="email" Type="Edm.String" Nullable="false"/>
<Property Name="gender" Type="Edm.String" Nullable="false" MaxLength="40" FixedLength="false"/>
<Property Name="ip_address" Type="Edm.String" Nullable="false" MaxLength="40" FixedLength="false" Unicode="true"/>
</EntityType>
</Schema>
<Schema Namespace="databinding.PersonsData.Model" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
<EntityContainer Name="PersonEntities" m:IsDefaultEntityContainer="true" p6:LazyLoadingEnabled="true"
xmlns:p6="http://schemas.microsoft.com/ado/2009/02/edm/annotation">
<EntitySet Name="Persons" EntityType="PersonsData.Invoice"/>
</EntityContainer>
</Schema>
</edmx:DataServices>

How does odata know which property is the ID?

In the following example russelwhyte is the id, but how does the provider know to map it to the UserName property?
URL: http://services.odata.org/V4/TripPinServiceRW/People?$format=application/json;odata.metadata=full
Response:
{
#odata.context: "http://services.odata.org/V4/(S(ck3fzk3dze0kmzjcruxiz31i))/TripPinServiceRW/$metadata#People",
#odata.nextLink: "http://services.odata.org/V4/TripPinServiceRW/People?%24format=application%2fjson%3bodata.
metadata%3dfull&%24skiptoken=8",
value:
[
{
#odata.type: "#Microsoft.OData.SampleService.Models.TripPin.Person",
#odata.id: "http://services.odata.org/V4/TripPinServiceRW/People('russellwhyte')",
#odata.etag: "W/"08D17DBDFB9CCAAC"",
#odata.editLink: "http://services.odata.org/V4/TripPinServiceRW/People('russellwhyte')",
UserName: "russellwhyte",
FirstName: "Russell",
LastName: "Whyte",
...
Friends#odata.associationLink: "http://services.odata.org/V4/TripPinServiceRW/People('russellwhyte')/Friends/$ref",
Friends#odata.navigationLink: "http://services.odata.org/V4/TripPinServiceRW/People('russellwhyte')/Friends",
...
},
...
]
}
By overriding GetEntityByKey of the base class EntitySetController
Query the metadata document, you can get the model schema for the service, and in which you can find which properties are the keys/IDs.
For example:
GET: http://services.odata.org/V4/(S(ksn5grnrgbebt44osly5z2vr))/TripPinServiceRW/$metadata
<EntityType Name="Person" OpenType="true">
<Key>
<PropertyRef Name="UserName"/>
</Key>
<Property Name="UserName" Type="Edm.String" Nullable="false">
<Annotation Term="Org.OData.Core.V1.Permissions">
<EnumMember>Org.OData.Core.V1.Permission/Read</EnumMember>
</Annotation>
</Property>
<Property Name="FirstName" Type="Edm.String" Nullable="false"/>
<Property Name="LastName" Type="Edm.String" Nullable="false"/>
<Property Name="Emails" Type="Collection(Edm.String)"/>
<Property Name="AddressInfo" Type="Collection(Microsoft.OData.SampleService.Models.TripPin.Location)"/>
<Property Name="Gender" Type="Microsoft.OData.SampleService.Models.TripPin.PersonGender"/>
<Property Name="Concurrency" Type="Edm.Int64" Nullable="false">
<Annotation Term="Org.OData.Core.V1.Computed" Bool="true"/>
</Property>
<NavigationProperty Name="Friends" Type="Collection(Microsoft.OData.SampleService.Models.TripPin.Person)"/>
<NavigationProperty Name="Trips" Type="Collection(Microsoft.OData.SampleService.Models.TripPin.Trip)" ContainsTarget="true"/>
<NavigationProperty Name="Photo" Type="Microsoft.OData.SampleService.Models.TripPin.Photo"/>
</EntityType>

The entity type <class> is not part of the model for the current context

This is a MODEL first approach. I have already researched this extensiely and have not come up with an answer. I have tried all the suggestions at the following links:
This appears to be the same problem but with no resolution
The entity type <classname> is not part of the model for the current context
These are the links I have already researched so please don't answer as duplicate of ----
EF 4.1 Code First error - The entity type SomeType is not part of the model for the current context
The entity type is not part of the model, EF 5
Here is the EDMX (Abbreviated for brevity):
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx">
<!-- EF Runtime content -->
<edmx:Runtime>
<!-- SSDL content -->
<edmx:StorageModels>
<Schema Namespace="Insight_Model.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">
<EntityContainer Name="Insight_ModelStoreContainer">
<EntitySet Name="vwCompanyHeader" EntityType="Insight_Model.Store.vwCompanyHeader" store:Type="Views" store:Schema="dbo" store:Name="vwCompanyHeader">
<DefiningQuery>SELECT
[vwCompanyHeader].[ID] AS [ID],
[vwCompanyHeader].[Name] AS [Name],
[vwCompanyHeader].[Active] AS [Active],
[vwCompanyHeader].[Creator] AS [Creator],
[vwCompanyHeader].[Created] AS [Created],
[vwCompanyHeader].[Modifier] AS [Modifier],
[vwCompanyHeader].[Modified] AS [Modified]
FROM [dbo].[vwCompanyHeader] AS [vwCompanyHeader]</DefiningQuery>
</EntitySet>
<EntitySet Name="vwWorkOrderHeader" EntityType="Insight_Model.Store.vwWorkOrderHeader" store:Type="Views" store:Schema="dbo" store:Name="vwWorkOrderHeader">
<DefiningQuery>SELECT
[vwWorkOrderHeader].[ID] AS [ID],
[vwWorkOrderHeader].[Active] AS [Active],
[vwWorkOrderHeader].[Name] AS [Name],
[vwWorkOrderHeader].[Creator] AS [Creator],
[vwWorkOrderHeader].[Created] AS [Created],
[vwWorkOrderHeader].[Modifier] AS [Modifier],
[vwWorkOrderHeader].[Modified] AS [Modified],
[vwWorkOrderHeader].[Leader] AS [Leader],
[vwWorkOrderHeader].[LeadTakenDate] AS [LeadTakenDate],
[vwWorkOrderHeader].[ProjectID] AS [ProjectID],
[vwWorkOrderHeader].[ProjectName] AS [ProjectName],
[vwWorkOrderHeader].[WorkOrderStatus] AS [WorkOrderStatus],
[vwWorkOrderHeader].[WorkOrderSubStatus] AS [WorkOrderSubStatus],
[vwWorkOrderHeader].[WorkOrderType] AS [WorkOrderType],
[vwWorkOrderHeader].[WorkOrderSubType] AS [WorkOrderSubType],
[vwWorkOrderHeader].[WorkOrderPriority] AS [WorkOrderPriority],
[vwWorkOrderHeader].[RefNumber] AS [RefNumber],
[vwWorkOrderHeader].[Request] AS [Request]
FROM [dbo].[vwWorkOrderHeader] AS [vwWorkOrderHeader]</DefiningQuery>
</EntitySet>
</EntityContainer>
<EntityType Name="vwCompanyHeader">
<Key>
<PropertyRef Name="ID" />
</Key>
<Property Name="ID" Type="int" Nullable="false" />
<Property Name="Name" Type="varchar" Nullable="false" MaxLength="50" />
<Property Name="Active" Type="bit" Nullable="false" />
<Property Name="Creator" Type="varchar" Nullable="false" MaxLength="51" />
<Property Name="Created" Type="date" Nullable="false" />
<Property Name="Modifier" Type="varchar" Nullable="false" MaxLength="51" />
<Property Name="Modified" Type="date" Nullable="false" />
</EntityType>
<EntityType Name="vwWorkOrderHeader">
<Key>
<PropertyRef Name="ID" />
</Key>
<Property Name="ID" Type="int" Nullable="false" />
<Property Name="Active" Type="bit" Nullable="false" />
<Property Name="Name" Type="varchar" Nullable="false" MaxLength="15" />
<Property Name="Creator" Type="varchar" Nullable="false" MaxLength="51" />
<Property Name="Created" Type="date" Nullable="false" />
<Property Name="Modifier" Type="varchar" Nullable="false" MaxLength="51" />
<Property Name="Modified" Type="date" Nullable="false" />
<Property Name="Leader" Type="varchar" Nullable="false" MaxLength="51" />
<Property Name="LeadTakenDate" Type="date" Nullable="false" />
<Property Name="ProjectID" Type="int" Nullable="false" />
<Property Name="ProjectName" Type="varchar" Nullable="false" MaxLength="15" />
<Property Name="WorkOrderStatus" Type="varchar" Nullable="false" MaxLength="35" />
<Property Name="WorkOrderSubStatus" Type="varchar" Nullable="false" MaxLength="35" />
<Property Name="WorkOrderType" Type="varchar" Nullable="false" MaxLength="35" />
<Property Name="WorkOrderSubType" Type="varchar" Nullable="false" MaxLength="35" />
<Property Name="WorkOrderPriority" Type="varchar" Nullable="false" MaxLength="35" />
<Property Name="RefNumber" Type="varchar" Nullable="false" MaxLength="25" />
<Property Name="Request" Type="varchar" Nullable="false" MaxLength="1500" />
</EntityType>
</Schema></edmx:StorageModels>
<!-- CSDL content -->
<edmx:ConceptualModels>
<Schema Namespace="Insight_Model" Alias="Self" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
<EntityContainer Name="Insight_Entities" annotation:LazyLoadingEnabled="false">
<EntitySet Name="CompanyHeaders" EntityType="Insight_Model.CompanyHeader" />
<EntitySet Name="WorkOrderHeaders" EntityType="Insight_Model.WorkOrderHeader" />
</EntityContainer>
<EntityType Name="CompanyHeader">
<Key>
<PropertyRef Name="ID" />
</Key>
<Property Type="String" Name="Name" MaxLength="50" FixedLength="false" Unicode="false" Nullable="false" />
<Property Type="Boolean" Name="Active" Nullable="false" />
<Property Type="String" Name="Creator" Nullable="false" MaxLength="51" FixedLength="false" Unicode="false" />
<Property Type="DateTime" Name="Created" Nullable="false" />
<Property Type="String" Name="Modifier" Nullable="false" MaxLength="51" FixedLength="false" Unicode="false" />
<Property Type="DateTime" Name="Modified" Nullable="false" />
<Property Type="Int32" Name="ID" Nullable="false" />
</EntityType>
<EntityType Name="WorkOrderHeader">
<Key>
<PropertyRef Name="ID" />
</Key>
<Property Type="Int32" Name="ID" Nullable="false" />
<Property Type="Boolean" Name="Active" Nullable="false" />
<Property Type="String" Name="Name" Nullable="false" MaxLength="15" FixedLength="false" Unicode="false" />
<Property Type="String" Name="Creator" Nullable="false" MaxLength="51" FixedLength="false" Unicode="false" />
<Property Type="DateTime" Name="Created" Nullable="false" />
<Property Type="String" Name="Modifier" Nullable="false" MaxLength="51" FixedLength="false" Unicode="false" />
<Property Type="DateTime" Name="Modified" Nullable="false" />
<Property Type="String" Name="Leader" Nullable="false" MaxLength="51" FixedLength="false" Unicode="false" />
<Property Type="DateTime" Name="LeadTakenDate" Nullable="false" />
<Property Type="Int32" Name="ProjectID" Nullable="false" />
<Property Type="String" Name="ProjectName" Nullable="false" MaxLength="15" FixedLength="false" Unicode="false" />
<Property Type="String" Name="WorkOrderStatus" Nullable="false" MaxLength="35" FixedLength="false" Unicode="false" />
<Property Type="String" Name="WorkOrderSubStatus" Nullable="false" MaxLength="35" FixedLength="false" Unicode="false" />
<Property Type="String" Name="WorkOrderType" Nullable="false" MaxLength="35" FixedLength="false" Unicode="false" />
<Property Type="String" Name="WorkOrderSubType" Nullable="false" MaxLength="35" FixedLength="false" Unicode="false" />
<Property Type="String" Name="WorkOrderPriority" Nullable="false" MaxLength="35" FixedLength="false" Unicode="false" />
<Property Type="String" Name="RefNumber" MaxLength="25" Nullable="false" FixedLength="false" Unicode="false" />
<Property Type="String" Name="Request" Nullable="false" MaxLength="1500" FixedLength="false" Unicode="false" />
</EntityType>
</Schema>
</edmx:ConceptualModels>
<!-- C-S mapping content -->
<edmx:Mappings>
<Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2008/09/mapping/cs">
<EntityContainerMapping StorageEntityContainer="Insight_ModelStoreContainer" CdmEntityContainer="Insight_Entities">
<EntitySetMapping Name="CompanyHeaders">
<EntityTypeMapping TypeName="Insight_Model.CompanyHeader">
<MappingFragment StoreEntitySet="vwCompanyHeader">
<ScalarProperty Name="ID" ColumnName="ID" />
<ScalarProperty Name="Modified" ColumnName="Modified" />
<ScalarProperty Name="Modifier" ColumnName="Modifier" />
<ScalarProperty Name="Created" ColumnName="Created" />
<ScalarProperty Name="Creator" ColumnName="Creator" />
<ScalarProperty Name="Active" ColumnName="Active" />
<ScalarProperty Name="Name" ColumnName="Name" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
<EntitySetMapping Name="WorkOrderHeaders">
<EntityTypeMapping TypeName="Insight_Model.WorkOrderHeader">
<MappingFragment StoreEntitySet="vwWorkOrderHeader">
<ScalarProperty Name="Request" ColumnName="Request" />
<ScalarProperty Name="RefNumber" ColumnName="RefNumber" />
<ScalarProperty Name="WorkOrderPriority" ColumnName="WorkOrderPriority" />
<ScalarProperty Name="WorkOrderSubType" ColumnName="WorkOrderSubType" />
<ScalarProperty Name="WorkOrderType" ColumnName="WorkOrderType" />
<ScalarProperty Name="WorkOrderSubStatus" ColumnName="WorkOrderSubStatus" />
<ScalarProperty Name="WorkOrderStatus" ColumnName="WorkOrderStatus" />
<ScalarProperty Name="ProjectName" ColumnName="ProjectName" />
<ScalarProperty Name="ProjectID" ColumnName="ProjectID" />
<ScalarProperty Name="LeadTakenDate" ColumnName="LeadTakenDate" />
<ScalarProperty Name="Leader" ColumnName="Leader" />
<ScalarProperty Name="Modified" ColumnName="Modified" />
<ScalarProperty Name="Modifier" ColumnName="Modifier" />
<ScalarProperty Name="Created" ColumnName="Created" />
<ScalarProperty Name="Creator" ColumnName="Creator" />
<ScalarProperty Name="Name" ColumnName="Name" />
<ScalarProperty Name="Active" ColumnName="Active" />
<ScalarProperty Name="ID" ColumnName="ID" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
</EntityContainerMapping>
</Mapping>
</edmx:Mappings>
The repository code:
Imports System.Linq.Expressions
Imports System.Data.Entity.Infrastructure
Imports System.Data.Entity
Public Class Repository(Of T As {Class, IEntity})
Implements IRepository(Of T)
#Region "Attributes"
Private objectContext As IDatabaseContext
Protected objectSet As IDbSet(Of T)
#End Region
Public Sub New(objContext As IDatabaseContext)
objectContext = objContext
objectSet = objectContext.Set(Of T)()
End Sub
Public Function FindAll() As IQueryable(Of T) Implements IRepository(Of T).FindAll
Return objectSet
End Function
Public Function FindWhere(predicate As Expressions.Expression(Of System.Func(Of T, Boolean))) As System.Linq.IQueryable(Of T) Implements Interfaces.IRepository(Of T).FindWhere
Return objectSet.Where(predicate)
End Function
Public Function FindById(id As Integer) As T Implements IRepository(Of T).FindById
Return objectSet.Single(Function(o) o.ID = id)
End Function
Public Sub Add(newEntity As T) Implements IRepository(Of T).Add
objectSet.Add(newEntity)
End Sub
Public Sub Remove(entity As T) Implements IRepository(Of T).Remove
objectSet.Remove(entity)
End Sub
Public Function Count(Optional predicate As Expression(Of Func(Of T, Boolean)) = Nothing) As Integer Implements IRepository(Of T).Count
Return If((predicate Is Nothing), objectSet.Count, objectSet.Where(predicate).Count)
End Function
Public Function Exist(Optional predicate As Expression(Of Func(Of T, Boolean)) = Nothing) As Boolean Implements IRepository(Of T).Exist
Return If((predicate Is Nothing), objectSet.Any, objectSet.Where(predicate).Any)
End Function
End Class
The DatabaseContext code:
Imports System.Data.Entity
Imports Insight.DataLayer.Interfaces
Imports System.Data.Objects
Imports System.Configuration
Public Class DatabaseContext
Inherits DbContext
Implements IDatabaseContext
Const defaultConnectStringName = "Insight_Entities"
Public Sub New()
Me.New(ConfigurationManager.ConnectionStrings(defaultConnectStringName).ConnectionString)
End Sub
Public Sub New(connectionString As String)
MyBase.New(connectionString)
MyBase.Configuration.LazyLoadingEnabled = False
MyBase.Configuration.ProxyCreationEnabled = False
End Sub
Public Overloads Sub SaveChanges() Implements Interfaces.IDatabaseContext.SaveChanges
MyBase.SaveChanges()
End Sub
Public Overloads Function [Set](Of T As Class)() As System.Data.Entity.IDbSet(Of T) Implements Interfaces.IDatabaseContext.Set
Return MyBase.Set(Of T)()
End Function
End Class
And the 2 class files:
WorkOrderHeader:
Imports System.ComponentModel.DataAnnotations
Imports System.Collections.ObjectModel
Imports System.Runtime.Serialization
Imports System.Data.Services.Common
Partial Public Class WorkOrderHeader
Inherits DataTransferObjectHeaderBase
Public Sub New()
End Sub
Public Sub New(iID As Integer, sName As String, bActive As Boolean, sCreator As String, dtCreated As DateTime, sModifier As String, dtModified As DateTime, sLeader As String, dtLeadTaken As Date, iProjectID As Integer, sProjectName As String, sWorkOrderStatus As String, sWorkOrderSubStatus As String, sWorkOrderType As String, sWorkOrderSubType As String, sWorkOrderPriority As String, sRequest As String)
Me.New(iID, sName, bActive, sCreator, dtCreated, sModifier, dtModified, sLeader, dtLeadTaken, iProjectID, sProjectName, sWorkOrderStatus, sWorkOrderSubStatus, sWorkOrderType, sWorkOrderSubType, sWorkOrderPriority, "", sRequest)
End Sub
Public Sub New(iID As Integer, sName As String, bActive As Boolean, sCreator As String, dtCreated As DateTime, sModifier As String, dtModified As DateTime, sLeader As String, dtLeadTaken As Date, iProjectID As Integer, sProjectName As String, sWorkOrderStatus As String, sWorkOrderSubStatus As String, sWorkOrderType As String, sWorkOrderSubType As String, sWorkOrderPriority As String, sRefNumber As String, sRequest As String)
ID = iID
Name = sName
Active = bActive
Creator = sCreator
Created = dtCreated
Modifier = sModifier
Modified = dtModified
Leader = sLeader
LeadTaken = dtLeadTaken
ProjectID = iProjectID
ProjectName = sProjectName
WorkOrderStatus = sWorkOrderStatus
WorkOrderSubStatus = sWorkOrderSubStatus
WorkOrderType = sWorkOrderType
WorkOrderSubType = sWorkOrderSubType
WorkOrderPriority = sWorkOrderPriority
RefNumber = sRefNumber
Request = sRequest
End Sub
<DataMember()> _
Public Property Leader() As String
Get
Return _leader
End Get
Set(value As String)
_leader = value
End Set
End Property
Private _leader As String
<DataMember()> _
Public Property LeadTaken() As Date
Get
Return _leadTaken
End Get
Set(value As Date)
_leadTaken = value
End Set
End Property
Private _leadTaken As Date
<DataMember()> _
Public Property ProjectID() As Int32
Get
Return _projectID
End Get
Set(value As Int32)
If (_projectID <> value) Then
_projectID = value
End If
End Set
End Property
Private _projectID As Int32
<DataMember()> _
Public Property ProjectName() As String
Get
Return _projectName
End Get
Set(value As String)
If (_projectName <> value) Then
_projectName = value
End If
End Set
End Property
Private _projectName As String
<DataMember()> _
Public Property WorkOrderStatus() As String
Get
Return _workOrderStatus
End Get
Set(value As String)
_workOrderStatus = value
End Set
End Property
Private _workOrderStatus As String
<DataMember()> _
Public Property WorkOrderSubStatus() As String
Get
Return _workOrderSubStatus
End Get
Set(value As String)
_workOrderSubStatus = value
End Set
End Property
Private _workOrderSubStatus As String
<DataMember()> _
Public Property WorkOrderType() As String
Get
Return _workOrderType
End Get
Set(value As String)
_workOrderType = value
End Set
End Property
Private _workOrderType As String
<DataMember()> _
Public Property WorkOrderSubType() As String
Get
Return _workOrderSubType
End Get
Set(value As String)
_workOrderSubType = value
End Set
End Property
Private _workOrderSubType As String
<DataMember()> _
Public Property WorkOrderPriority() As String
Get
Return _workOrderPriority
End Get
Set(value As String)
_workOrderPriority = value
End Set
End Property
Private _workOrderPriority As String
<DataMember()> _
Public Property RefNumber() As String
Get
Return _refNumber
End Get
Set(value As String)
_refNumber = value
End Set
End Property
Private _refNumber As String
<DataMember()> _
Public Property Request() As String
Get
Return _request
End Get
Set(value As String)
_request = value
End Set
End Property
Private _request As String
End Class
#End Region
CompanyHeader:
Imports System.ComponentModel.DataAnnotations
Imports System.Collections.ObjectModel
Imports System.Runtime.Serialization
Imports System.Data.Services.Common
<DataServiceKey("ID")> _
<MetadataTypeAttribute(GetType(CompanyHeader.CompanyHeaderMetadata))> _
Partial Public Class CompanyHeader
Inherits DataTransferObjectHeaderBase
Friend NotInheritable Class CompanyHeaderMetadata
'Metadata classes are not meant to be instantiated.
Private Sub New()
MyBase.New()
End Sub
<DataMember()> _
Public Property Active As Boolean
<DataMember()> _
Public Property ID As Integer
<DataMember()> _
Public Property Created As DateTime
<DataMember()> _
Public Property Creator As String
<DataMember()> _
Public Property Modified As DateTime
<DataMember()> _
Public Property Modifier As String
<DataMember()> _
Public Property Name As String
End Class
Public Sub New()
End Sub
Public Sub New(iID As Integer, sName As String, bActive As Boolean, sCreator As String, dtCreated As DateTime, sModifier As String, dtModified As DateTime)
ID = iID
Name = sName
Active = bActive
Creator = sCreator
Created = dtCreated
Modifier = sModifier
Modified = dtModified
End Sub
End Class
Unit Test Code:
<TestMethod()> _
Public Sub WorkOrderServiceTests_TestConnectivityThruService5()
Dim woService As New DatabaseContext
Dim woHeaders = New Repository(Of WorkOrderHeader)(woService)
Dim woTests = New Repository(Of WorkOrderTest)(woService)
Dim coHeaders = New Repository(Of CompanyHeader)(woService)
Assert.IsTrue(woHeaders.Count <> 0)
End Sub
Things I have tried to resolve the issue:
1) Checked database - Both queries return data correctly.
select * from vwWorkOrderHeader
select * from vwCompanyHeader
2) Deleted WorkOrderHeader from the EDMX then recreated it from database.
3) MOQed out the DBContext to make sure that it isn't the service query doing something funny. This correctly returns the object, so it means that it is something at the context level or below.
4) Stepped through both tests to ensure that they use the same method of building the context - Thy do.
4) Stepped through both tests to ensure that they use the same method of building the repository - Thy do.
5) The only difference is during the following Function of DatabaseContext:
Public Overloads Function [Set](Of T As Class)() As System.Data.Entity.IDbSet(Of T) Implements Interfaces.IDatabaseContext.Set
Return MyBase.Set(Of T)()
End Function
The WorkOrderHeader code has the following in the watch for MyBase.Set(Of T)()
{System.Data.Entity.DbSet(Of Insight.Model.WorkOrderHeader)} System.Data.Entity.DbSet(Of Insight.Model.WorkOrderHeader)
The CompanyHeader code has the following in the watch for MyBase.Set(Of T)()
{SELECT [Extent1].[Name] AS [Name], [Extent1].[Active] AS [Active], [Extent1].[Creator] AS [Creator], [Extent1].[Created] AS [Created], [Extent1].[Modifier] AS [Modifier], [Extent1].[Modified] AS [Modified], [Extent1].[ID] AS [ID] FROM (SELECT [vwCompanyHeader].[ID] AS [ID], [vwCompanyHeader].[Name] AS [Name], [vwCompanyHeader].[Active] AS [Active], [vwCompanyHeader].[Creator] AS [Creator], [vwCompanyHeader].[Created] AS [Created], [vwCompanyHeader].[Modifier] AS [Modifier], [vwCompanyHeader].[Modified] AS [Modified] FROM [dbo].[vwCompanyHeader] AS [vwCompanyHeader]) AS [Extent1]} System.Data.Entity.DbSet(Of Insight.Model.CompanyHeader)
I am at a complete loss on this one and am entering my 3rd day of working on the same problem. I am hoping that some fresh eyes on the problem might see an error that I have made or point me in a direction of testing the problem that I have not thought of.
UPDATE:
I removed the service code to ensure it was something in the DBContext. I have isolated the service out of the equation so that only the repositories are being used and they are all using the same DatabaseContext, so it can't be anything related to the connection string. I verified that in the Model Browser under Insight_Model/EntityContainer:Insight_Entities/Entity Sets/WorkOrderHeaders exists and that under Insight_Model/Entity Types/WorkOrderHeader exists. It almost appears as though the DatabaseContext isn't even attempting to query the conceptual model for the entity set.
After 3 (4) days (depending on how you view days, I separate days by when I sleep and not necessarily when the sun goes down/comes up), I found the answer. In the EDMX file above, I have a column named LeadTakenDate, in the WorkOrderHeader class, I used the field name LeadTaken. This was a stupid error on my part.
How can this benefit you possibly? Here is how I resolved the problem:
First I isolated the problem to exactly one area by MOQing out parts to see how far down the rabbit hole the problem was. Once I figured out the problem was in the DatabaseContext, I wrote a test case that created a working and a non working use case. This isolated the problem and allowed me to test theories to fix it quicker. I tried a thousand different things before trying to use the EF 5.x persistance ignorant poco generator. I commented out all of my code in the WorkOrderHeader class and copied the generated code in. Reran my tests and they worked, so I started uncommenting my properties and commenting out the generated code then rerunning my test until I hit the appropriate property.
The error message is cryptic enough that is can be very difficult to trouble shoot.