silverlight - "Entity does not have a key defined" error in working production code -


we running odd problem: using entity framework 4 , ria services silverlight 5 appliation hosted in iis 6.1. long periods of time, running smoothly, application fails following error message in event log:

webhost failed process request.
sender information: system.servicemodel.activation.hostedhttprequestasyncresult/56703158
exception: system.servicemodel.serviceactivationexception: service '/services/ecofleet-domainservices-repository-ecofleetrepository.svc' cannot activated due exception during compilation.
exception message is: entity 'devicedata' in domainservice 'ecofleetrepository' not have key defined. entity types exposed domainservice operations must have @ least 1 public property marked keyattribute.. ---> system.invalidoperationexception: entity 'devicedata' in domainservice 'ecofleetrepository' not have key defined. entity types exposed domainservice operations must have @ least 1 public property marked keyattribute.
@ system.servicemodel.domainservices.server.domainservicedescription.validateentitytypes()
@ system.servicemodel.domainservices.server.domainservicedescription.initialize()
@ system.servicemodel.domainservices.server.domainservicedescription.createdescription(type domainservicetype)
@ system.collections.concurrent.concurrentdictionary2.getoradd(tkey key, func2 valuefactory)
@ system.servicemodel.domainservices.server.domainservicedescription.getdescription(type domainservicetype)
@ system.servicemodel.domainservices.hosting.domainservicehost..ctor(type domainservicetype, uri[] baseaddresses)
@ system.servicemodel.domainservices.hosting.domainservicehostfactory.createservicehost(type servicetype, uri[] baseaddresses)
@ system.servicemodel.activation.servicehostfactory.createservicehost(string constructorstring, uri[] baseaddresses)
@ system.servicemodel.servicehostingenvironment.hostingmanager.createservice(string normalizedvirtualpath, eventtraceactivity eventtraceactivity)
@ system.servicemodel.servicehostingenvironment.hostingmanager.activateservice(serviceactivationinfo serviceactivationinfo, eventtraceactivity eventtraceactivity)

@ system.servicemodel.servicehostingenvironment.hostingmanager.ensureserviceavailable(string normalizedvirtualpath, eventtraceactivity eventtraceactivity)

--- end of inner exception stack trace ---
@ system.runtime.asyncresult.end[tasyncresult](iasyncresult result)
@ system.servicemodel.activation.hostedhttprequestasyncresult.end(iasyncresult result) process name: w3wp
process id: 2300

the application still responds, no entities can loaded server. after stopping , starting site, works again.

the entity in case (devicedata) database table, , does have key, , regardless seems random entity fails. furthermore expect see "key not defined" error @ compile time. have clue problem is, , how fix it?

your devicedata entity not have key defined, required. should create property name id or devicedataid treated key convention (entity framework looks these properties). can use mappings set other property key. can achieved data annotations attributes:

[key] public int foo { get; set; } 

or fluent mappings:

modelbuilder.entity<devicedata>().haskey(d => d.foo); 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -