Firebird entity framework errow while generate model from database - entity-framework

I had to import data from firebird database to Entity Framework, in order to do so I'v installed .net provider and DDEX Provider for visual studio.
My problem occurs when I was adding any table to model the erros says
"Key Part: 'SomeColumn' for type MyTable is not valid. All parts of the key must be non nullable.**"
It does't matter if I'am trying to import one table or many tables, I always had the same error.
What I have to do ?
Any Ideas ? I will appreciate any help.

I solved the problem.
All I need to do is right click on model.edmx ->Open with ->XML Text Editor and remove all but one which is appropiate ID of table.

Related

Entity Framework "Invalid object name 'Item_id'"

I have a solution that has spontaneously started generating the error "Invalid object name 'Item_id'". I have searched for this but all answers seem related to code first issues around pluralization; my project is database first.
The context is that there is a Purchase with a collection of ItemPurchaseLines which are linked to Items. The error occurs when a new purchase is generated, this generates new ItemPurchaseLines and either links them to existing Items or generates new Items. The mapping between ItemPurchaseLines and Items is via a foreign key on Item_Id to Id respectively.
I have regenerated the model from the database and the relationships/column mappings all look good.
Any help, or any further information you need, would be appreciated.
Edit
I have built a LinqToSql alternative and it gives exactly the same error.
OK - I am a complete idiot!
I completely forgot that I added a trigger to the relevant table to update the pl_Items table but instead of using the correct table name I used Item_Id.
So the code from VS was all good it was the SQL Trigger in the back and that was screwing things up!

Entity Framework 5 renaming - Database First

I'm using Database First approach and I have table called Campus and when I add to my edmx from SQL Server and I see that it renamed to Campu why is that doing?
I'm guessing that your project is having some table pluralization problems. So when your table Campus is created, Entity Framework is literally reading it as an entity called a Campu that you have pluralized to be Campus.
See this link on how to change pluralization.
But this isn't really a problem right? You can change your model name back to Campus.

Entity Framework Cardinality Issue on a 0...1 Association

I have database tables that look like this:
A Task can be mapped to a Module, or not mapped at all (0...1). I'm using Entity Framework database-first, and when I generated the model from the database, the Task entity came through with Modules as a collection (0 or more). So I opened up my EDMX and changed the "Modules" navigation property on Task to 0...1.
Now, when I attempt to compile, I get this error:
Error 3003: Problem in mapping fragments starting at line 1241:Given the cardinality of Association End Member Task, it should be mapped to key columns of the table TaskModule. Either fix the mapping or change the multiplicity of this end.
I don't understand what I need to do to fix this. I've looked at the association details and can't see the issue. I know I'm probably missing something stupid, but am totally stuck. Association properties:
Visual Studio 2010 SP1, Entity Framework 4.3.1.0, SQL Server 2008 R2.
One way to do this is to redefine the primary key for the TaskModule table. Instead of the primary key being (TaskId, ModuleName) it needs to be just (TaskId). Then do an update model from database and change any of the associations manually that didn't get picked up from that update.
Well your database schema is not correct with the description you give :
the TaskModule table implicates a many-to-many relationship, not a many-to-oneOrZero.
In edmx, many-to-many relation tables are not displayed, but they still exist in database.
So you should fix your database, or be happy with the relation proposed by EF !

Entity Framework: deleted SQL table is not removed from the model

Seemingly simple thing got me completely frozen and I can't find anything on the Net about this:
I had a common many to many relationship in my db:
Table One + TableTwo + LinkingTable with 2 columns: TableOneID and TableTwoID
I deleted the LinkingTable and tried to update the model from database. Now I get error "Error 11007: Entity type 'LinkingTable' is not mapped."
Does anyone know what exactly this EF wants? Thank you!
Right-click the Model in the Solution Explorer. Select "Open with..." Select "XML (Text) Editor" in the dialog. Remove all nodes and references of the LinkingTable (or whatever its real name is) from the model's xml. Close all model files that are currently opened (I know, weird). Build the project. Open the model again. Everything should be fine now.
Open Model Browser,
In the Entity types, select the table which is to be deleted,
It will remove all the associations with the table.
It worked well for me.

EF4 is throwing an error "Schema specified is not valid"

I'm getting a weird EF4 "Entity Framework v4" error when I do a select on the context:
Schema specified is not valid. Errors:
The relationship 'AnalyzerConfigurationModel.FK_AnalyzerMetadataParameters_AnalyzerMetadata' was not loaded because the type 'AnalyzerConfigurationModel.AnalyzerMetadataParameter' is not available.
The query to generate the error is:
Using context As New AnalyzerConfigurationEntities
Dim EFAnalyzerConfiguration = (From P In context.AnalyzerConfigurations
Where P.Name = analyzerConfigurationName).FirstOrDefault
End Using
The schema is show below.
I've checked the connection strings, multiple times, its not that. Everything looks fine. I'm not sure if the XML that gets generated from this schema is off or not. But looked there too and don't see anything off or different from other properties. Has anyone run into this one before?
I found that if I expanded the EDMX file in solution explorer (VS 2012) and right clicked on each .tt file and selected Run Custom Tool also fixed the issue. This might be easier than de
Also make sure you're referencing project has the EntityFramework installed otherwise the dependent code will get this error.
https://www.nuget.org/packages/EntityFramework
Let me explain this:
The problem is because the system did not find consistency of the columns in database, the entities in the .edmx file and the model class and also the use of the same in the controller class.
So follow the following steps to fix this up:
Go to the database, check all the column names and properties.
Confirm them with the class diagram in the.edmx file. Right-click on the class in which you are getting the error, and select update option for the class. Select the Refresh tab in dialogue (if there is no new column added. if new column is added, you can select the add tab.) and select the relevant objects. Generally they are tables. So select them and finish.
Next check the names in the model class and the controller class.
This should be the solution. If not, let me know.
Are you using the SelfTracking Entity T4 template? I had this issue and found out the T4 template was not re-generating my entities after I had changed the Entity model in the Entity Designer. Try to right click the T4 Template and click "Run custom tool", and see if that helps.