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
2
votes
3 answers

Entity Framework 6 Fluent Mapping - One to Many Code First

Given the following SQL tables: EntityGroup: Id int, (PK) GroupName nvarchar(100) Entity: Id int, (PK) EntityGroupId int, (FK Non-nullable) Description nvarchar(100) And the following POCOs public class Entity { public int Id { get; set;…
Marcus K
  • 779
  • 1
  • 10
  • 22
2
votes
0 answers

Defining conditional relationships

Are there any ways to configure conditional navigations in EF6 code-first (or EDMX, for that matter). I have an entity type that will be referenced my multiple other types. An attachment belongs to either a Person or a Vehicle. A person or a vehicle…
2
votes
2 answers

Can't set the Relation between 2 DB Models

I Got This Issue: I Have the Application User Class Like This public class ApplicationUser : IdentityUser { public ROLES Role { get; set; } public int? CompanyId { get; set; } public int? AreaId { get; set; } …
1
vote
1 answer

Several foreign keys in same table EF Core 7

I have two entities CodeMaster and Employee. In Employee, I have more foreign key optional properties to navigate to the CodeMaster entity. When I insert data into Employee, I get this error: Inner Exception 1: SqlException: The INSERT statement…
1
vote
2 answers

Include mapping table property reference with LINQ query

I have following Schema in EF Code First Architecture. Class Teacher public class Teacher { [Key] public int Teacher_PK { get; set; } public string Name { get; set; } public int Age { get; set; } public virtual ICollection
Dave
  • 156
  • 1
  • 1
  • 14
1
vote
2 answers

How to upload image in ASP.Net core code first approach and send image using post man

This is my model class public class ImageModel { [Key] public int ImageId { get; set; } [Column(TypeName = "nvarchar(50)")] public string Title { get; set; } [Column(TypeName = "nvarchar(100)")] [DisplayName("Image Name")] …
1
vote
0 answers

Add extended property to tables and columns using Entity Framework Code First

I am using Entity Framework Code First to design my database. I am wondered if there is a way to add extended property to my tables and columns using entity framework, so I can use my code docs in database. That would be great.
1
vote
1 answer

DbSet.AddAsync is setting an id value on an identity column causing an exception

I have this a class Order, it has relation with other 2 classes but the issue is with the Id here public class Order { public int Id { get; set; } public bool IsDeleted { get; set; } public string CreatedBy { get; set; } public…
Zinov
  • 3,817
  • 5
  • 36
  • 70
1
vote
0 answers

No mapping to a relational type can be found for property 'Identity.User.LockoutEnd' with the CLR type 'Nullable'

I want to create a migration for creating a new table in my database but after executing the Add-Migration MsSql_Add_ArticleCategory_Table, I got this error: No mapping to a relational type can be found for property …
1
vote
1 answer

Why is a shadow property being generated when this model implements IEnumerable?

I have the following model classes: public class Farmer { public int ID { get; set; } public Box Box { get; set; } } public class Apple { public int BoxID { get; set; } public Box Box { get; set; } public int Number { get {…
1
vote
0 answers

Soft deleted child objects appear in parent objects list

I'm using Entity Framework Core 2.2 code first. Soft delete is implemented in the overriden Context class. There is an UnitOfWork class that initializes Repositories for specific entities, while taking the Context as argument in constructor. Some of…
Armino
  • 129
  • 1
  • 1
  • 11
1
vote
1 answer

How to map EF object through mapping table

I have two database tables -- Customer_Values and Customer_Attributes... and it's... dumb. Terrible. Customer_Values has things like CustomerId | AttributeId | Value -------------------------------- 01 | 01 | Steve 02 | …
1
vote
0 answers

How to load only IDs when use many-to-many relationship in Entity Framework?

I have the following models: class Item { public ICollection GroupIds { get; set; } // Introduced for EF only public ICollection Groups { get; set; } } class Group { public ICollection ItemIds { get; set; } …
1
vote
2 answers

The data reader is incompatible. A member of the type, 'RoleId', does not have a corresponding column in the data reader with the same name

Stored procedure works and deletes what I want but I still get this error after deleting: The data reader is incompatible with the specified 'AMSIdentity.Models.RemoveRoleFromUserViewModel'. A member of the type, 'RoleId', does not have a…
1
vote
1 answer

Multiplicity conflict while setting up Entity Framework

I have a more complicated question here But thought I would simplify it. Here are my dummied classes (the structure this is based on comes from the NDC so I don't have control over it): public class RightHand { [Key] public int RightHandId {…
Gina Marano
  • 1,773
  • 4
  • 22
  • 42