Questions tagged [ef-model-builder]

58 questions
1
vote
3 answers

Entity Framework - Fluent API - Creating Weird Columns PK : FK FK

My project is Database First and I'm using Entity Framework 6.2.0. So I have following classes in simple illustration: Person [1] [n] Link_Table [n] [1] Area ====== ========== ==== ID ID …
sandy
  • 464
  • 1
  • 6
  • 13
1
vote
0 answers

Invalid column name 'UserId' and 'IdentityUser_Id' when trying to log-in/register

I have been trying to build my own online shop in MVC based on the OpenOrderFramework located here - https://github.com/lbacaj/OpenOrderFramework I've managed to get everything working perfectly apart from when it comes to trying to log in,…
1
vote
0 answers

How can i Modify identity user tables on visual studio

I have created an Web Appplication project on Visual Studio and it has created some default tables for my database like UserRoles-Claims etc. How can i modify them to change their PK or the attributes they hold. I tried using Fluent API but i could…
1
vote
1 answer

1:1 self relation in EF

I have a object of type ScheduleItem public class ScheduleItem : EntityBase { [MaxLength(500)] [Required] public string TitleAr { get; set; } [MaxLength(300)] [Required] public string TitleEn {…
Ra'ed Alaraj
  • 173
  • 1
  • 15
1
vote
0 answers

The number of properties in the Dependent and Principal Roles in a relationship constraint must be identical

I am trying to create one-to-many relation between 2 classes and mainly I am trying to set a composite key between room number and campusid. I have tried using annotations and overriding the modelbuilder, but still nothing worked... This is the…
1
vote
3 answers

One to zero...one relationship

I can't seem to get the relationship between Foo and Bar right. public class Foo { [Key] public int Id { get; set; } public int Name { get; set; } public virtual Bar Bar { get; set; } } public class Bar { [Key] public int…
Beakie
  • 1,948
  • 3
  • 20
  • 46
1
vote
0 answers

See Create database queries by modelBuilder

currently I am working at a project which requires to be backwards compatible with (non-EF) databases, but also want to create a new database from model. For this task I save the current schema somewhere (in XML form) and update the databases with…
DevilSuichiro
  • 1,049
  • 8
  • 21
1
vote
1 answer

model builder add one column more?

I use EF code first. It's my modelbuilder protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Conventions.Remove(); modelBuilder.Entity() …
0
votes
0 answers

EF Core 7.0.5 model and its object property to same table

I have a model in which 3 classes (part of the complete model) public class City { public int Id { get; set; } public string Name { get; set; } public string District { get; set; } } public class Customer { public string? Id { get;…
0
votes
1 answer

EFCore owned model has object property mapped to foreignKey

I have a model in which 3 classes (part of the complete model) I want to have 2 model classes to the same table(split table), when the owned class has ForeignKey to the third class. but when I tried to configure the ForeignKey I got error:…
0
votes
1 answer

How to keep previously added data when adding new data using seed in .net core?

First I have added data using modelBuilder in database. enter image description here and after this I have applied add-migration command and update-database command. Now if I try to add new data of Id-6, then it is deleting previously added…
Jack Ray
  • 41
  • 3
0
votes
0 answers

Change tablename of entity on-the-fly

I want to modify the mapping of an entity to a table, the moment I use the model, not at design time. Is this possible? Context: I have an entity 'ProductPicture' mapped to its table with the same name this table is actually an inventory of…
0
votes
1 answer

Entity Framework Map() property alternate in EF Core 6

I am migrating my project from Entity Framework to EF Core 6 but now I am stuck at this point. modelBuilder.Entity() .HasMany(e => e.tblUsers) .WithMany(e => e.tblStoreGroups) .Map(m =>…
0
votes
1 answer

Unable to determine the relationship represented by navigation 'Role.CreatedBy' of type 'User'

I am using .NET 6 to develop EF Core MVC program, The concept is single User can have multiple roles, and the role data is create by a User from another system. I have a base class EntityBase.cs : public abstract class EntityBase { public int Id…
0
votes
0 answers

EF Core : build one-to-one relationship between two base classes

I have two base classes where each base class has inherited subclasses: [Table("BaseClassOne")] public class BaseClassOne { public Guid Id { get; set; } public BaseClassTwo BaseTwo { get; set;…
SNO
  • 793
  • 1
  • 10
  • 30