I am programming both MVC Web application and WCF application to connect them together and both of them work perfectly,however after connecting them I get an exception in mvc application and the exception Exactly:
"System.Data.Entity.Core.MetadataException" occurred in EntityFramework.dll, but was this not processed in the user code.
Additonal information the main webapplication rule is to add and manage user with asp.net Entity using two data base connection the locaö database and the Remote datavase.
the Wcf application connected to the remote database and it is role to transmit information from the webapplication to the remote database.
the webapplication without the connection with the WCF work Perfectly but after I add the Reference to my WCF it stop working with this exception.
inner error:
The scheme is not valid. Error:
The assignment of the CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'tab_OnlineUserClaim'. Previously found CLR type
'ELVIRA_Userverwaltung.ServiceReference1.tab_OnlineUserClaim', newly found CLR type 'Userverwaltung.Models.tab_OnlineUserClaim'. The assignment of the CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'tab_OnlineUserLogin'. Previously found CLR type 'ELVIRA_Userverwaltung.ServiceReference1.tab_OnlineUserLogin', newly found CLR type 'Userverwaltung.Models.tab_OnlineUserLogin'.
This means that the application is unable to load the EDMX.
You might have changed the MetadataArtifactProcessing property of the
model to Copy to Output Directory.
The connection string could be wrong. I know you say you haven't changed it, but if you have changed other things (say, the name of an
assembly), it could still be wrong.
You might be using a post-compile task to embed the EDMX in the assembly, which is no longer working for some reason.
In short, there is not really enough detail in your question to give an accurate answer, but hopefully these ideas should get you on the right track.
Related
I am developing an application in which the database is selected by the end user at runtime. The database can either be on a MS SQL server or an IBM DB2 server. I am currently using IBM DB2 10 Express-c on a windows server for testing. I am developing using Visual Studio 2013 C# and Entity Framework 6. I have installed the EntityFramework.IBM.DB2 Nuget package for the DB2 support. I am using reverse-engineer code-first against an existing SQL server database to generate my base code. The application works fine against a SQL Server database.
I am using System.Data.Common.DbProviderFactories.GetFactory to generate the provider.
System.Data.EntityClient.EntityConnectionStringBuilder connectString = new System.Data.EntityClient.EntityConnectionStringBuilder(a_Connection);
System.Data.Common.DbConnection conn = System.Data.Common.DbProviderFactories.GetFactory(connectString.Provider).CreateConnection();
conn.ConnectionString = connectString.ProviderConnectionString;
LB500Database = new LB402_TestContext(conn, true);
a_Connection is provider=IBM.Data.DB2;provider connection string="Database=LISTBILL;User ID=xxxx;Password=yyyy;Server=db210:50000"
and is being parsed correctly by the EntityConnectionStringBuilder.
I then try to access a table in the database with
LBData500.LB_System oneSystem;
System.Linq.IQueryable<LB_System> allSystem = LB500Database.LB_System.Where(g => g.DatabaseVersion == databaseVersion && g.CompanyID == companyID);
I get an invalid operation exception "Sequence contains no matching element" which means that no elements are returned. If I remove the Where so that all rows are returned (there is one in the table) and try to enumerate the result set using the VS debugger I see the message:
"The context cannot be used while the model is being created. This exception may be thrown if the context is used inside the OnModelCreating method or if the same context instance is accessed by multiple threads concurrently. Note that instance members of DbContext and related classes are not guaranteed to be thread safe."
I am not using multi-threading. I am not inside the OnModelCreating.
Just changing the connect string to point to SQL server works fine, so I think my basic approach is sound. If I were getting some kind of error back from the server I would have something to go on. I can run the query from inside Visual Studio, so I have connectivity.
Any pointers would be appreciated.
UPDATE:
I turns out the EF objects were generated using EF5 and the EF6 runtime was being used. I regenerated the EF objects using EF6 reverse engineer code first. I can now connect to the database and get an error message:
"ERROR [42704] [IBM][DB2/NT64] SQL0204N \"DBO.LB_SYSTEM\" is an undefined name."
The schema in the DB2 database is the same as my userid (in this case, not always). I added the CurrentSchema=xxxx to the provide connection string, but EF is still passing dbo as the schema name.
Now I need a way to change the schema name at run time. I saw a link to codeplex EFModelAdapter (http://efmodeladapter.codeplex.com). So I may give that a try.
Update2 After looking through EFModelAdapter, I decided to take a different route. Since I only need database access and not schema management, I decided to go with Dapper (https://github.com/StackExchange/dapper-dot-net). This works great for what I need and allows me to change the schema name when accessing DB2 databases.
As per my Update 2, Entity Framework was a little overkill for what I needed. I switched to dapper https://github.com/StackExchange/dapper-dot-net and I am working fine against multiple DBMSs.
When I try to ask a service - I get an exception
Unable to load metadata for return type
'System.Linq.IQueryable'
Inet says that service can not find model files. But I use code-first, and have no such files.
I use Microsoft.Data.Services.
You can say that my connection string is wrong.
But when I try to init myDbContext, my database is created without tables.
No breakpoints after creation context have been hit.
What can I do???
You may be missing datamember attributes in fields and datacontract attribute in class.
It is best to have some light class between your db and wcf ,so that you can add special attributes or create complex entities to use in wcf endpoints.
Just info if you are missing something about EF Code First & WCF Data Service.
There are two assemblies for creating and consuming WCF Data Services
in the .NET Framework 4: System.Data.Services.dll and
System.Data.Services.Client.dll. If you try to use these with a
DbContext and Code First classes, they won’t work out of the box. The
issue is with DbContext, not Code First. DbContext didn’t exist when
those assemblies were built, so they don’t understand it.
Resolution is either use ObjectContext (DbConext use ObjectcContext under the cover)
[OR]
Use March 2011 CTP that contained fixed-up assemblies (Microsoft.Data.Services.dll and Microsoft.Data.Services.Client.dll) that know how to work with the DbContext.
Checkout msdn article for details:
http://msdn.microsoft.com/en-us/magazine/hh852588.aspx
I am having trouble getting related entities to be loaded on the client using RIA Services and EF 4.1 with Silverlight.
I'm currently using the Include() method on my DbDomainService with an Expression parameter and am finding that when stepping through my service the related entities are loaded just fine. However, when the Queryable results are returned to the client NO related entities are loaded - they are null. All of my entities are marked with the [DataMember] attribute so I have assumed that it isn't a serialization issue. Moreover, my DbDomainService query method is marked with the [Query] attribute.
I was wondering if there is anything specific that has to be set up on the client when using RIA Services with EF 4.1 code first? I must be missing something, but I'm not sure what.
Any help would be appreciated.
Thanks,
sfx
While you may have used the .Include() in your service call, you also have to add the [Include] attribute in the metadata class that is also created.
The .Include() statement tells EF to generate the SQL necessary to retrieve the data, while the Include attribute tells WCF RIA Services to make sure the Entity Class is also created on the client.
Once the data arrives at the client, it needs to know what type of structure to put it in as well.
HTH
I am consuming OData WCF Data Service in my iPad application. I am able to add an object to the Entity at my server side but unable to add NSData field to the SQL Server image data field.
I am not getting any error while adding and saving the object at remote side.
can you help me how can I send NSData type value to SQL server image data type field using OdataSDK ?
I managed to upload a byte[] (NSData) file by using the ODataSDK for Objective-C by configuring my OData service to provide a Stream Service Provider. I started from a Visual Studio project that had my SQL Server tables mapped with the Entity Framework, so that OData already exposed the entities to save/read to.
It's important to note that the entity that has the file byte must have the m:hasStream attribute set in the Entity Framework .edmx file, which can be done only by manually editing the XML file (Have a look at this tutorial, which is made of three parts: here's the first )
Once you do so, the ODataSDK for ObjC provides the methods setSaveStream (and getReadStream) to save (and read) the NSData file (although I had some problems getting getReadStream to work, but it may be due to the fact that it was my first implementation of such service).
If you are uploading files larger than 64KB, have a look at this answer to properly configure your Web.config: https://stackoverflow.com/a/6907582/423816
Of course you also have to use the addObject: and saveChanges: methods, but this is what you'd do with any other OData entity.
Hope this helps
This question is an extension of another question, but I think it warrants its own thread. See See Silverlight Question
I have a stored procedure (SQL 2005) that returns a dynamic data set (different columns/schema) each time it is called.
I want to consume this in Silverlight 3.0 so I need to somehow wire this up using Entity Framework and RIA Services. I also need this to be Bindable (Silverlight Grid) so I need these dynamic columns to be accessible via properties (grid limitation). Any ideas?
In the currently shipping version of the Entity Framework, the only type of stored procedures you can map are those which return entity types. The mapping is done, generally, before you compile, although it seems at least theoretically possible to generate Entity Framework metadata at runtime.
Therefore, I see a few choices.
Give up on the whole idea of consuming a procedure which does not return a defined schema. You will never be able to map such a procedure before you compile.
Dynamically generate EDMX at runtime in order to map an entity type to the expected output columns of the procedure before you invoke. Note that the current version of the Entity Framework is a bit finicky about the columns a procedure returns; you can find documentation about this on MSDN.
In .NET 4.0, there are new features which allow you to inform the Entity Framework about your client schema at runtime without having to generate EDMX first. You might be able to leverage these features in order to map some entity type to the expected output columns of the procedure.
Again, in .NET 4.0, there may be support for procs which return scalar values. I can't remember if this is the case or not.
You can always get a standard database connection from the entity connection and execute the procedure directly, using regular SqlCommands. Unfortunately, this makes your code database-provider-specific, but it may be the simplest solution to your problem. Indeed, using such a procedure at all is already database-server-specific.
You might use a WCF web service wraper for accesing your SP and use the WCF service as data source Brad Abrams has a way to do that on his series of articles on RIA Services