Questions tagged [ef-code-first-mapping]

Relating to using the fluent mapping API of Entity Framework Code first for configuring the SQL that gets generated on running migrations.

93 questions
0
votes
1 answer

Refactor a large generated method into smaller methods?

Using EF 6 and "Code First from database" it generates a "OnModelCreating" that is 20k lines approximately 688k of code against our large (650+ tables) database. This causes IIS to append as it is larger than the 32-bit 256kb stack limit. I do not…
CmdrTallen
  • 2,264
  • 4
  • 28
  • 50
0
votes
0 answers

Entity Framework Fluent API - Map Many to Many relationship, and query from it

After reading extensively in this topic, I wanted to implement a multiple many-many relationship of my own. Here is my used case: FYI: Although, there is no FK relationship between Program and Provider, Program.ProvID and Provider.ProvID act as…
0
votes
1 answer

Add Migration not working in Visual Studio 2017

I am creating a Web API application using EF with a code-first approach in Visual Studio 2017. I tried to use enable-migration, initially I was not working so I installed these packages. Install-Package Microsoft.EntityFrameworkCore.Tools -Version…
0
votes
3 answers

Column names in each table must be unique. Column name 'department_Id' in table 'UserLogins' is specified more than once

class UserLogin { [Key] public int id { get; set; } [StringLength(50)] public string userName { get; set; } [StringLength(20)] public string password { get; set; } public virtual Modules module { get; set; } …
0
votes
1 answer

Is it possible to link a table FK to 2 other PK in entity framework?

I have a shopping cart that is to receive items from two separate tables. One table contains single items and the other contains Boxes of several items. I am using an ApiController to insert the item into the cart, problem being that when I insert a…
0
votes
1 answer

Introducing FOREIGN KEY constraint 'XYZ_ID' on table 'XXX' may cause cycles or multiple cascade paths in mvc core

I am getting this error in code first MVC CORE while inserting this and I am doing Code first for very first Time command: Update-Database -Context ProjectDbContext "Introducing FOREIGN KEY constraint 'FK_Product_SubCategory_SubCategoryId' …
0
votes
1 answer

How to make a one to many relation ship Using EF Core (Repository Pattern)

i am trying to make relation "Student has many StudentRecords" using repository pattern. when i run migration facing below error.Kindly let me know what should i do in on model Creating method. "The property 'Student.StudentRecord' is of type…
0
votes
1 answer

Entity Framework how to map composite entities?

I'm newbie in EF and i have such question: I have four Entities, which describe the elements of the address: public partial class Region : BaseEntity { private ICollection _regionCities; public string Code { get; set; } …
Asator
  • 20
  • 4
0
votes
1 answer

How to make primary key from 2 Foreign keys in MySql EFCore

i have some issue with making primary key from 2 foregin keys model examples: Element, Color, ElementToColor ElementToColor should contain 2 foregin keys that representing the Element and Color relation [Key,Column(Order = 1)] public Int ElementId…
Leon Barkan
  • 2,676
  • 2
  • 19
  • 43
0
votes
1 answer

getting error for a table which I did not create using Entity Framwork Code first approach. error is invalid object name "XXXX"

Initial migration code is below where I never create dbo.StudentEvent1 but I get error when I run my asp.net MVC application using this database. CreateTable( "dbo.StudentEvents", c => new { …
0
votes
1 answer

Entity Framework 6: How to map array elements to table columns

[I'm surprised that I didn't find an existing question with an answer to this conceptual question. Maybe I just didn't search the right keywords.] Consider an entity type "Singer" with some of its own properties. Next, consider an entity type…
0
votes
1 answer

Create user and set navigation properties using ApplicationUserManager.CreateAsync

I'm using ASP.NET Identity 2.0 and Entity Framework with a Code First approach. When I create an instance of ApplicationUserManager and calll the CreateAsync method, all is fine if my users' properties are all of primitive types: User user = new…
Ed Graham
  • 4,306
  • 3
  • 30
  • 30
0
votes
2 answers

How to solve Code First from database many-to-many mapping in Entity Framework?

Bellow code snippet showing my scenario: [Table("User")] public partial class UserModel { public UserModel() { UserRole = new HashSet(); } public int UserID { get; set; } public string FullName { get; set; } public…
0
votes
1 answer

Implement Row Level security column in inherited tables

I'm using Entity Framework with a code-first approach to generate the database. I have introduced row-Level security in SQL Server. I want to create 3 tables where all the common properties go to ItemVersion and document related properties to…
0
votes
0 answers

The entity set or function import 'My_Table' is not defined in the entity container

I´m using code first, a database with about 60 tables, the error on the title occurs on 3 tables and i dont understand why... int count_manual = db.Database.SqlQuery("select count(*) from My_Table").Single(); // This works int count =…
Sergio
  • 8,125
  • 10
  • 46
  • 77