ProviderIncompatibleException with Entity Framework - entity-framework

I always get this error when I issue this command
http://localhost:19572/api/courses
This method is generating the exception
public IQueryable GetAllCourses()
{
return _ctx.Courses
.Include(“CourseSubject”)
.Include(“CourseTutor”)
.AsQueryable();
}
Exception:
System.Data.Entity.CoreProviderIncompatibleExceptionoccurred inEntityFramework.dll` but was not handled in user code
Additional information An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct.
and when I inspect the JSON element in Fiddler I always get this
ExceptionMessage=The system cannot find the file specified
ExceptionType=System.ComponentModel.Win32Exception
Message=An error has occurred.
I am using Entity Framework 6.0.1, and I have tried 5 but it didn’t work so I there any thing wrong with Entity Framework version or what?

Related

Azure Data Explorer C# querying and ORM

I looked into querying data from DotNet and found: https://github.com/Azure/azure-kusto-samples-dotnet samples.
I see no ORM examples there and this got me to try something myself
public class KustoContext : DbContext
{
public KustoContext(KustoConfiguration kustoConfiguration)
: base(new KustoConnectionStringBuilder(kustoConfiguration.ClusterUri, kustoConfiguration.DatabaseName)
.WithAadApplicationKeyAuthentication(kustoConfiguration.ClientId, kustoConfiguration.ClientSecret, kustoConfiguration.TenantId)
.ConnectionString)
{
}
public DbSet<SomeEntity> SomeEntities{ get; set; }
}
Unfortunately, I get an error:
Exception thrown: 'System.ArgumentException' in System.Data.dll
An unhandled exception of type 'System.ArgumentException' occurred in System.Data.dll
Keyword not supported: 'application client id'.
This makes sense, I guess I need a provider for adx, but I couldn't find a NuGet package for that.
Ideally, I would like to use Entity Framework with Azure Data Explorer. Is this possible? Are there any available samples?
UPDATE: are there any alternatives for Entity Framework?
Ideally, I would like to use Entity Framework with Azure Data Explorer. Is this possible? Are there any available samples?
I don't believe anyone has written an Entity Framework provider for Azure Data Explorer.

WebApi uncaught error when calling SaveChanges() for breezeJs

Have Breeze setup with WebAPI and EntityFramework.
EntityManager queries working fine.
SaveChanges() working fine on all entities, EXCEPT...
I have an entity with an optional related entity:
Public Class Payment
Public Property Id As Integer
Public Overridable Property Registree As Registree
Public Property RegistreeId as Integer?
Public Property Amount as Double
End Class
Here is my WebAPI action for SaveChanges()
<HttpPost()>
Public Function SaveChanges(bundle As JObject) As SaveResult
Dim result As SaveResult
Try
result = breezeDb.SaveChanges(bundle)
Catch ex As Exception
Dim err = ex
End Try
Return result
End Function
When I create a new Payment entity in Breeze and call SaveChanges, everything works fine UNLESS my payment entity has a value for RegistreeId.
If RegistreeId has a value, the following happens:
SaveChanges() on the WebAPI is successfully called.
No errors are caught in my Try/Catch.
The "result" returned to the client has no errors associated with it.
However, on client side, the manager.saveChanges() fails, giving an error object with NO details, just "The response had HTTP status code 500."
return manager.saveChanges()
.then(function(saveResult){
return saveResult;
})
.catch(errorOnSave); //this gets called, no breakpoints get hit in the "then" function
NOTE: The entity IS getting saved correctly to the database, related entity and all. So this is not a foreign key constraint or other database problem.
So it seems something is breaking on the server and no error message is getting to client. But my try/catch is not getting it, and the error ONLY happens if that optional foreign key field is NOT null.
Any ideas?
Found the problem...didn't realize I had not turned off Custom Errors in web.config.
<system.web>
<customErrors mode="Off" />
...
</system.web>
Then I was able to see that Json.Net was running into null exception error when parsing the saveresult.

Getting User authority error (_ERR_USER_AUTHORITY) on handler databean mapping in WCS

I have created a REST handler which was mapped to a data bean.
And I am calling the databean using this method
executeConfigBasedBeanWithContext(dataBeanName, profileName, responseFormat,
typedProperty);
Now, on calling this handler, I am getting the below Exception:
EC_APPLICATION_EXCEPTION like The user does not have authority to
execute this query (_ERR_USER_AUTHORITY).
But it was working for Admin users(wcsadmin) without any exception.
Below is the REST Exception:
{"errors":[{"errorParameters":["com.xxxx.commerce.order.command.CodeDataBean"],"errorCode":"CWXFR0268E","errorKey":"NOT_AUTHORIZED_FOR_QUERY","errorMessage":"CWXFR0268E:
You are not authorized to execute query: GET
https://localhost/wcs/resources/store/10154/codedata"}]}
Am I missing anything here?
Per the IBM documentation
If you are using remote binding through REST service calls, and the
data bean does not implement the Delegator interface, only a Site
Administrator can run the service call by default. This can be
customized by overriding the isSiteResource(DataBean) method of the
REST Resource Handler class.
http://www.ibm.com/support/knowledgecenter/SSZLC2_7.0.0/com.ibm.commerce.webservices.doc/concepts/cwvrestsecurityauth.htm?lang=en

How to read Wildfly resteasy deserialization error from client?

My Wildfly resteasy service is working fine, or was until I made a code change. No big deal, now I'm getting a deserialization error: "Problem deserializing 'setterless' property ..."
My question is whether there is anyway to get an error message in the client. I'm getting a Status of 400, and I can test that, but I'd like to get any message if possible. Any ideas?
If I get an error in the user code, I can set an error message in the header, but since there is a deserialization problem, the server is throwing a error before getting to any user code.
You can use an ExceptionMapper to handle the response returned to the client. JAX-RS has an exception hierarchy that will map to different responses and status codes. 400 in JAX-RS is a BadRequestException. So you could do something like
#Provider
public class BadRequestExceptionMapper
implements ExceptionMapper<BadRequestException> {
#Override
public Response toResponse(BadRequestException e) {
Response response = Response.status(Response.Status.BAD_REQUEST)
.entity("Sorry I forgot to implement a Setter").build();
return response;
}
}
This isn't a very great example, because BadRequestException is thrown for many other reasons, than just forgetting a setter (or deserialization), but it demonstrates how you can intercept the response after the exception is thrown.
See RestEasy Exception Handling
Jersey User Guider has a better explanation
See Exception Hierarchy

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

We are running into a very odd problem: We are using entity framework 4 and ria services for a silverlight 5 appliation hosted in IIS 6.1. For long periods of time, everything is running smoothly, but occasionally the application fails with the following error message in the event log:
WebHost failed to process a request. Sender Information:
System.ServiceModel.Activation.HostedHttpRequestAsyncResult/56703158
Exception: System.ServiceModel.ServiceActivationException: The service
'/Services/EcoFleet-DomainServices-Repository-EcofleetRepository.svc'
cannot be activated due to an exception during compilation. The
exception message is: The Entity 'DeviceData' in DomainService
'EcofleetRepository' does not have a key defined. Entity types exposed
by DomainService operations must have at least one public property
marked with the KeyAttribute.. ---> System.InvalidOperationException:
The Entity 'DeviceData' in DomainService 'EcofleetRepository' does not
have a key defined. Entity types exposed by DomainService operations
must have at least one public property marked with the
KeyAttribute. at
System.ServiceModel.DomainServices.Server.DomainServiceDescription.ValidateEntityTypes()
at
System.ServiceModel.DomainServices.Server.DomainServiceDescription.Initialize()
at
System.ServiceModel.DomainServices.Server.DomainServiceDescription.CreateDescription(Type
domainServiceType) at
System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey
key, Func2 valueFactory) at
System.ServiceModel.DomainServices.Server.DomainServiceDescription.GetDescription(Type
domainServiceType) at
System.ServiceModel.DomainServices.Hosting.DomainServiceHost..ctor(Type
domainServiceType, Uri[] baseAddresses) at
System.ServiceModel.DomainServices.Hosting.DomainServiceHostFactory.CreateServiceHost(Type
serviceType, Uri[] baseAddresses) at
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String
constructorString, Uri[] baseAddresses) at
System.ServiceModel.ServiceHostingEnvironment.HostingManager.CreateService(String
normalizedVirtualPath, EventTraceActivity eventTraceActivity) at
System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(ServiceActivationInfo
serviceActivationInfo, EventTraceActivity eventTraceActivity)
at
System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String
normalizedVirtualPath, EventTraceActivity eventTraceActivity)
--- End of inner exception stack trace --- at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult
result) Process Name: w3wp Process ID: 2300
The application still responds, but no entities can be loaded from the server. After stopping and starting the site, everything works again.
The entity in this case (DeviceData) is a database table, and it does have a key, and regardless it seems to be random which entity fails. Furthermore I would only expect to see the "key not defined" error at compile time. Does anyone have a clue what the problem is, and how to fix it?
Your DeviceData entity do not have key defined, which is required. You should create property with name Id or DeviceDataId which will be treated as key by convention (Entity Framework currently looks for these properties). Also you can use mappings to set other property as key. This can be achieved with data annotations attributes:
[Key]
public int Foo { get; set; }
Or with fluent mappings:
modelBuilder.Entity<DeviceData>().HasKey(d => d.Foo);
First you won't have an error at compile time because it is not a mandatory thing, but not having one might give you quite the headache, because EF use it in many ways. so you have to redefine your key by naming it Id or DeviceDataId(Using the convention) or define a one from the model.
It seems from your question that there is a key defined for DeviceData, in that case I advice you to relook the properties of the key column in your model.
remember also that not having a key column might reduce the performance of your app.