Relating to using the fluent mapping API of Entity Framework Code first for configuring the SQL that gets generated on running migrations.
Questions tagged [ef-code-first-mapping]
93 questions
0
votes
1 answer
ef core 2 - Introducing FOREIGN KEY constraint 'X' on table 'Y' may cause cycles or multiple cascade paths
I know, I know, already exist many questions like that, but I dont find how can I solve this problem in my scenario.
I have a customer and a have a seller, a customer not necessary is a seller, but all seller is a customer.
In my order I have a…

Italo José
- 1,558
- 1
- 17
- 50
0
votes
0 answers
Mapping string collection with Entity Framework 6.1
How do I map a collection of strings to the database using EF6 Code First.
Here is my scenario. I have a book class with a collection of strings
public class Book
{
public int Id { get; set; }
public string Title { get; set; }
public…

Joe K
- 1
- 2
0
votes
2 answers
Entity Framework code-first foreign key to many to many table
I have this Scenario:
public class Table1
{
[Key]
public string Table1Code { get; set; }
public virtual List Table2 { get; set; }
}
public class Table2
{
[Key]
public string Table2Code { get; set; }
public virtual…

Marco
- 71
- 2
- 8
0
votes
0 answers
EF Code First Migration - Naming the column for complex type properties
I'm converting an existing EF model to use code first.
It has a number of Complex Types, that have a specific db field naming convention:
__
So for example, this Complex Type:
public class…

BG100
- 4,481
- 2
- 37
- 64
0
votes
1 answer
Entity B inherited from Entity A (using MapInheritedProperties ) breaks the relationship of A and C - Entity Framework Code First
I currently have 3 entities in my model Item, RegistroItem and ItemTienda: RegistroItem is inherited from Item and ItemTienda has a one-to-many relationship with Item. I configured the RegistrosItems Table using Fluent API like this:
protected…

Desmond
- 406
- 5
- 7
0
votes
1 answer
How EF detect model changes without migration history table
I am using entity framework code first migrations. Very first time I do not have migrations enabled. When I run the project it creates _migrationhistory table with one row in it.
Then I delete this table and ran application, it ran successfully.…

Rajaram Shelar
- 7,537
- 24
- 66
- 107
0
votes
0 answers
Update-Database for existing tables
My team has a database generated using Code First Migrations. The database is then populated with another script that can take upwards of an hour to run. I generate a .sql file of those tables with the populated data, this is to help speed up others…

Nick
- 978
- 1
- 12
- 28
0
votes
1 answer
Entity Framework - How to configure the User Roles Many to Many Relationship
Below is the definition of the User entity, there is a navigation property Roles
public class User
{
public User()
{
Roles = new List();
}
public string Id { get; set; }
public…

Carlos Liu
- 2,348
- 3
- 37
- 51
0
votes
1 answer
How do I set a custom reference column name in EF6 code-first?
Consider a simple microblogging platform with the data model defined as follows:
[Table("users")]
public class User
{
[Column("id"), Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; set; }
[Column("name"),…

Ivan
- 63,011
- 101
- 250
- 382
0
votes
0 answers
How can I load entities with complex types from a table-valued function?
I have a table-valued function that returns entities that contain complex types. I am trying to figure out the best way to load this data into my code-first application as entities.
I tried the Code First Functions project, but it doesn't support…

Kris Harper
- 5,672
- 8
- 51
- 96
0
votes
0 answers
LINQ: Invalid column name '*Id'
I got these error on those calls. I must be doing something wrong :-) but where?
On my controller I have this:
var faqs = _context.Faqs.Include(c=>c.Categories).ThenInclude(c=>c.category);
var forums = _context.Forums.Include(c =>…

Nicolas
- 1
- 1
- 5
0
votes
2 answers
EF: validation error for 1:0..1 relationship in data model with navigation properties
I have this simple data model of some reservations and theirs cancellations:
[Table("ReservationCreation")]
public class ReservationCreation
{
[Key()]
public int ReservationCreationId { get; set; }
…

xMaa
- 132
- 6
0
votes
1 answer
Can I have EF code first TPH with a non abstract base class?
In have a table in SQL Server defined by
CREATE TABLE [dbo].[ReportDataV2](
[ID] [int] IDENTITY(1,1) NOT NULL,
[DataTypeName] [nvarchar](max) NULL,
[IsInplaceReport] [bit] NOT NULL,
[PredefinedReportTypeName] [nvarchar](max)…

Kirsten
- 15,730
- 41
- 179
- 318
0
votes
0 answers
"Tricking" EF core to use unique key instead of primary key
I have a database at work that has tables without primary keys (Sql Server). It uses a different schema. It has a unique (sometimes compound) key for each table. I cannot modify database in any way. It is a vendor's database.
Is it ok to trick EF…

Rick Rat
- 1,732
- 1
- 16
- 32
0
votes
1 answer
EF Code first, how can you map a bidirectional one to one or zero relationship in EF?
I have two classes a User and an Image table:
public class User
{
public Guid? ImageId {get; set;}
public Image Image {get; set;}
}
public class Image
{
public Guid? UserId {get; set;}
public User User {get; set;}
}
Both the user…

SventoryMang
- 10,275
- 15
- 70
- 113