I have tried to scaffold a AspNetUserRoles table with AspNetUser, AspNetRoles and others tables that I need.
The scaffolding has a problem with many to many relationship of AspNetUserRoles and there is an error when application runs
System.InvalidOperationException: 'Cannot use table 'AspNetRoles' for entity type 'IdentityRole' since it is being used for entity type 'AspNetRole' and potentially other entity types, but there is no linking relationship. Add a foreign key to 'IdentityRole' on the primary key properties and pointing to the primary key on another entity type mapped to 'AspNetRoles'.'
Or other similar errors. I tried to handle AspNetRoles for a day.
I could scaffold a ASPNetUserRoles table only and copy paste it's fragment to my DbContext.
Is it the right way to add ASPNetUserRoles CRUD pages?
Related
Is it possible to update the the Primary Key of a table when using EF Core.
I have tried _context.Database.ExecuteSqlCommand with UPDATE statement as well as using a stored Proc and no joy, db.SaveChanges() gives the following error
System.InvalidOperationException: 'The property 'Id' on entity type 'Simulation' is part of a key and so cannot be modified or marked as modified.'
This is a one off job that needs to be done, I have temporarily modified the foreign keys to ON UPDATE CASCADE.
Is it possible with EF or should I just use ADO?
Thanks
I have two tables: users and estates
A user can be "linked" to multiple estates, and an estate can be "linked" to many users. To handle this manyToMany relationship, I created a "joinTable" estatesUsers in which the primary key is actualy a composite one involving the two foreign keys userId and estateId.
This was fine until I wanted to add extra fields to this table.
I read that when adding extra fields for such a table, the relationship is not a "manyToMany" anymore but two "oneToMany" relationship instead for each original entities.
My problem is that Doctrine still not consider this table (was the join table) and skip it when I run php app/console doctrine:mapping:import AppBundle yml
How can I get the command line tool to handle correctly those relationships and generate this new entity (the yml schema files) ?
Extra question: how do I command the tool (inside the yml schema files) to create a repository class for each entity before running php app/console doctrine:generate:entities MyBundle ?
Thank you !
SELECT DISTINCT TOP (100)
PERCENT country_Code, country_Name
FROM dbo.Location
Message 1 The table/view 'mixtapez.dbo.View_Select_Country' does not
have a primary key defined. The key has been inferred and the
definition was created as a read-only
table/view. E:\1C#asp.net\vuziq\vuziq\Projects\BannerSystem\WebBannerSystem\WebBannerSystem\Models\Model1.edmx 0 0 WebBannerSystem
The view works on others languages, so I dont want get Id by distinct, any idea?
It is just an informative message that Entity Framework created what it thinks is the primary key because any Entity Framework entity must have a primary key (that is .NET key, not SQL key). If you have read-only entity, the autogenerated key will probably work just fine for you. To be extra safe (and remove any chance the key does not work correctly), you should use NoTracking option for queries on this entity.
If you use .Distinct() in LINQ query that will go into your SQL query - the key Entity Framework uses does not play any role.
I have 2 tables that have a foreign-key relationship through the field that has nchar type.
Database designer successfully created relationship and displays it on database diagram. But entity model created doesn't have this relationship, and as a result dynamic data site doesn't allow automated filtering by that parameter.
Is it possible to force that relationship be mapped to entity data model?
If no, how to apply filter on that field?
Dav Check if your foreign table have primary key or not. I faced same problem but after adding primary key to foreign it got resolved. Please try once.
If still you are facing problem you can use FilterUIHint annotation to do it.
I have web application where Iam using linq to business entites i have business data model.
the problem is :
I have table with one column that it dosen't allow null value, when I try to update this table the folloeing error arise:
error The property 'e.g Carrier' is part of the object's key information and cannot be modified
what I can do?
The easiest thing to do is add a second column to the table that has a unique key eg guid and create a read only property on the entity that corresponds to it.
Linq to business entites needs some kind of key to keep track of what to update in the database. Usually this is the primary key on the database table. If you dont have a primary key it cannot reliably update the database and will then send you an exception.
Also if there is no primary key explicitly set on the table linq to business entites will select one of the columns (think its the first column in the table but i could be wrong) to act as a primary key and will therefore not allow you to update it.