I have a problem with a entity framework model. I couldn't find the answer also because i really don't know how to explain it well.
I have a User table anad a Rights table. There is a many-to-many relationship.
The EF User model has two properties: GrantedRights and RevokedRights.
From what i understood EF should create 2 tabel (one for the granted and the other for the revoked) with just the RightsID and the UserID.
But I can't find those tables, neither the context gives me the option. I didn't create the DB.
I'd like to know if there's an example code to follow to extract the list of GrantedRights from a user in this case..
Thanks
Related
In our app we have an entity, as per app design we have, the entity resides in 2 dbs. Conditionally we need to switch the source DB.
Further, though same entity the tables slightly differ in 2 databases. What would be the correct way to have eloquent models for this scenario?
As gone through several sites, Repository Model will be right choice when we have business entities that comes from multiple datasource.
I have two tables - ContactInformation & EmailAddress - which have a many to many (* : *) relationship. After making this association in the ADO.NET data model and generate the db from it, a table titled ContactInformationEmailAddresses which maps the two tables is created in the Entities Container.
Unlike when I scaffold views which have a 1:* relationship, there's no entries available for its counterpart in the view when I scaffold either one and scaffolding off the combined table isn't an option even after updating the model from the db.
My question is simply: is there an automated way to generate the creation form for ContactInformationEmailAddresses that will have the EmailAddress entry field?
At present the scaffolding templates don’t support generating views that require the selection and association with more than one entity – the “many” end of the association.
Make sure to check out this blog article
http://blogs.msdn.com/b/mcsuksoldev/archive/2013/09/20/managing-entity-relationships-with-mvc-scaffolding.aspx
I'm a bit confused how to work properly with many-to-many relationships in locally created objects.
I've prepared a small example to demonstrate the issue.
There are two tables and one mapping table:
And data in tables:
Entity Framework has created two tables and many-to-many relation:
Now run the application and load single student (with ID=1 and his classrooms).
If student was loaded from the database then everything is fine and EF gets 2 classrooms:
But in case user was created locally (with the same Id but changed Name) and attached to the EF then classrooms are not loaded (studentLocal variable).
The same situation if I try to load student from EF - it gets the local user (student variable has Name="xx") and no classrooms:
On the view user can change classrooms for student as well as change student properties so I need to update Student table and merge StudentClassroom table.
What is the best way to deal in this case? I don't want to load each
postback student entity again and again.
Is there a way to load
Classrooms for locally created Student which exist in the database?
How to merge StudentClassroom records? I know only one - load
existed records and new one and merge then either deleting all of
them and recreating from the new list either manually determining
which records should be deleted/updated/created. Is there a better
approach?
Your problem is that EF is not creating the right tables for your model. It should be creating 3 classes not 2. Probably the reason it isn't is that you don't have the relations set up properly in the database. If you are using SQL Server try using the diagram feature to check your relationships and Primary Keys are correctly set up before you set up the model.
I have category entity and subcategory entity. I need to get subcategory data to that related categoryId of category entity.
My category entity contains these attributes: "categoryId","categoryName"
subcategory contains: "subcategoryId","subcategoryName", "categoryId".
So can any one please guide me how can i put the relationship between this two entity ??
Thanks for advance.
Very first you are mixing the concepts of MySQL or SQLite with Core data. Unlike them Core Data does not have primary-foreign Key concept to relate entities(for easy understanding tables in MySQL). Just create relationship between those entities and you can fetch data their data.
Now about your Entities you have are category and subcategory. So you have to create relationship between them. If one category have many subcategories you have to check To many relationship option from Data Model Inspector..Otherwise One to One relationship would be the one you should go for..Have a look at screenshot how you can make your relationship one to many..
This is a good tutorial link for one to many relationship. You can refer if you do not know how to implement.
Also this for tutorial simple relationship in Core Data..
if you are beginner with Core data you can go with Quick Tutorial Start by Apple and you will get basic idea of Core data.
I understand in Entity Framework you can specify relationships that need to be joined with Include:
Product firstProduct =
db.Product.Include("OrderDetail").Include("Supplier").First();
But we have the opposite issue that a simple LINQ statement is getting making too many JOINs on the SQL server.
So how do we do the opposite, i.e. tell Entity to not do any deep loading of joined tables when it gets all the orders, so that on the SQL Server it executes:
SELECT * FROM Orders
The Entity Framework often goes ahead and loads basic relationship information too.
It does this so users can make updates easily, without violating the EF's unique concurrency policy for relationships.
You can turn this off however by doing a no tracking query.
See Tip 11 - How to avoid relationship span for more information for more information
Alex