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.
Related
I'm using .Net 4.5, entity framework 5, database first. I have a junction (many-to-many) table in my database. For this example lets say the table is "StudentsCourses":
Students
-PkStudentId
-Name
Courses
-PkCourseId
-CourseNumber
StudentsCourses
-FkStudentId
-FkCourseId
This works just fine right now. The 'generate model from database' creates a Student entity with a navigation property to the Course entity. But here is where the trouble is:
I need to add another column to the StudentsCourses table. Lets just call this column "CourseYear". So our junction table would now look like this:
StudentsCourses
-FkStudentId
-FkCourseId
-CourseYear
So, I've added this column to the database and ran "Update Model from Database" on the edmx. I would expect to see an entity created for StudentCourses, with a navigation property to both Students and Courses. But no such entity is created. I still see the same two tables (Students & Courses) with the same navigation property as before.
I've done a lot of reading and researching, but haven't really come across a clear-cut answer. There is a wealth of information on code-first which I can't apply to my scenario. Is there a way to get what I'm after? Is it as simple as adding a PkId to the StudentCourses table? SQL Replication is preventing me from doing this. I would think the composite should suffice, but maybe EF needs a PK to do it's magic? I read a little bit about manually setting relationships, but could not find anything speaking to my particular situation. It could be that I am just missing a simple step in the process of updating the edmx from database. I've done this plenty of times when: adding new tables, adding columns, deleting columns, etc. I'm following the same steps as I always do, but maybe I need to do something different in this case?
Thanks ahead of time for any help. It is greatly appreciated. Please let me know if any more information would help.
From what I've gathered it appears as though EF will not generate a model for a table that doesn't have a Primary Key.
I'm a bit late for this, but you have the answer in this thread Updating Entity Framework Model after adding a field to a previous look up only table
As they say here, you have to delete the relationship between Students and Courses in the designer. Then update your model from the database, and make sure StudentsCourses table is checked in the Tables branch of the Add tab.
I attempted to update my edmx file by selecting a table. The tool spit out a info message that said the table did not have a primary key.
The entity did not get added to the design surface but it did get added to the .edmx file. In addition, using the model browser I see an Entities.Store and an Entities. My table got added to Entities.Store, but not to Entities.
I cannot access the table that was "added" in the code.
What do I do?
Steps to reproduce:
Create a SQL table with two columns that are both defined as foreign keys to other tables. Make sure the tables that the FKs point to already exist in the model on the design surface.
Right click and choose Update Model from Database...
Next. Under the Add tab, mark the new table under Tables
Click Finish.
An association will be created and it will be selected on the design surface, but it won't start with FK_, it will just be the name of your table. Go to the Model Browser and look under Entity Types. The table will not be there. Look under Associations and you will see your table name there as an association, but it will look out of place (because of the name).
Entity Framework was too smart for me. It created an association instead of an entity. Odd, but it works for how I need to use it.
This is a really weird error, I have looked online and can not see any obvious reasons why this is happening.
I am using Database First Entity Framework version 5 and have added 4 tables called:
WorkStatus
JobStatus
SubJobStatus
SubJobStageStatus
JobStatus, SubJobStatus and SubJobStageStatus each has a foreign key constraint to WorkStatus.
I have updated my edmx to include these tables but for some reason each table is missing the last s from the word Status. So the tables and their navigation properties are now called:
WorkStatu
JobStatu
SubJobStatu
SubJobStageStatu
Does anyone know why this happens?
"-Status" is being interpreted as a plural, and Entity Framework is being "helpful" by de-pluralizing.
For example, if you have a table called "Customers" EF will generate an entity called "Customer", which is in fact nicer in code:
var customer = new Customer();
It isn't working out so well in your case; your tables are already singular.
You can rename your tables to "-Statuses" or update the names in the designer or disable pluralization:
Under Tools > Options
Entity framwork made a entity for each of my tables except for one, and I'm not sure why. I select it when i generate it from the database.
Here is my entity framework diagram, and the diagram in SQL:
http://imgur.com/a/zY17T
Notice how RecipeMeal is missing from entity framework. Does anyone have an idea why this might be happening?
RecipeMeal is supposed to store if a recipe is breakfast, lunch etc. It's not a column of Recipes because a recipe could be a lunch OR dinner recipe, as an example.
I am using EF 5.0
Thanks.
Entity Framework has built-in support for many-to-many relationships.
The table is exposed through the two ICollection<T> properties in Meal and Recipe.
I also found that if your table doesn't have a primary key it will also get skipped. One of my tables was just a summary table and didn't really need a primary key and it wouldn't be included in the reverse engineer. As soon as I added a primary key it was picked up.
I'm giving EF Model first a go. I'm using EF 4.1
Pretty much followed this article
I've set PluraliseNewObjects to False on the Model and also in Options->Database Tools ->O/R Designer set Pluralization of names to false.
Neither have any effect - when I generate a new schema from the model the table names are always pluralised - is it possible to disable this?
OK - I've found one way to achieve what I want - but it's a pretty daft route.
Generated db with the plural names (interesting that it only pluralised the tables mapping to types - not the auto-generated linking tables for many to many joins).
Manually renamed the tables in the database
Deleted Model from the project and recreated based on existing database schema (the one I've just renamed).
Model is now correctly mapped to singularly names tables.
I'll wait and see if anyone comes up with a more sensible way of achieving this....
The names of the tables in the generated DDL seem to match the "Entity Set Name" values (different than the "Entity Name"). If you singularize the Entity Set Names, the table names in the DDL are singularized as well.
This will have the possibly undesired effect of singularizing the EntitySet property names in your code, though. Instead of:
myDatabase
.Products
.Where...
.Select...
your code will look like:
myDatabase
.Product
.Where...
.Select...
may or may not be an issue