94 questions
0
votes
0
answers
60
views
EF Core does not allow Cascade Delete on 2 foreign keys, but Blazor sample web app does this just fine
I have seen countless posts advising that EF Core with SQL Server blocks multiple foreign keys which have "OnDelete Cascade" (due to cycles and multiple delete paths). However I see in the ...
0
votes
0
answers
38
views
EF core: Map Many to Many relationship without navigation property and on a none primary key
I have the entity:
public class UserQuestion
{
public Guid UserId { get; set; }
public bool HasCompletedQuestion { get; set; }
public Guid? QuestionInformationSetId { get; set; }
...
1
vote
1
answer
59
views
Reference one Table to "one of many" Table
I have a Table called Command
public class Command
{
public int Id { get; set; }
public CommandParameterBaseEntity Parameter { get; set; } = null!;
}
and two (or more) other tables with ...
1
vote
1
answer
274
views
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 ...
0
votes
1
answer
584
views
EF Core - multiple parents with a list of the same child (code first)
Is there any way to represent something like this :
public abstract class DbEntity
{
[Key]
public string Id { get; set; } // <-- a GUID-String created by the domain
}
public class Carrier :...
0
votes
0
answers
457
views
Configuring cascade delete throws error - Introducing FOREIGN KEY constraint on table may cause cycles or multiple cascade paths
I have the following entities:
public class CompanyRelationshipEntity
{
public int ParentCompanyId { get; set; }
public int ChildCompanyId { get; set; }
public CompanyEntity? ParentCompany ...
-2
votes
1
answer
88
views
Set one to one and one to many both relationships among two tables
I have two tables called employee and team. I want to set relationships among the tables as follows.
employee belongs to a team. (1: m relationship).
team has a team leader (team leader is also an ...
1
vote
2
answers
778
views
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; } ...
0
votes
1
answer
1k
views
When using Entity Framework 6 Code-First approach, can I create index directly from database?
I have a recommendation from Azure to create the following index:
CREATE NONCLUSTERED INDEX [nci_wi_Transactions_71EA7D20388C3F47A9B9EBF2A1C7BA0C] ON [dbo].[Transactions] ([Client_Id]) INCLUDE ([Date],...
0
votes
1
answer
548
views
Find entities not in many-to-many relation
I might be looking at this the wrong way but I have a basic many-to-many code-first setup in EF Core 3.1 with Department <-> DepartmentDay <-> Day.
modelBuilder.Entity<DepartmentDay>(...
1
vote
2
answers
1k
views
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(...
0
votes
1
answer
34
views
ASP.NET Core MVC code-first complex relation with enumerated value and index
I have a project where I need a complex relationship:
public enum InputFileTypes
{
unknown = 0,
ConfirmationFile = 1,
PrestationFile = 2,
EOCChoiceFile = 3,
EOCReplaceFile = 4,
...
0
votes
1
answer
273
views
CodeFirst EF Core - Implementing interfaces possible?
I'm a little new to code-first in EF Core and I'm trying a few things out and I'm a little confused how to implement the below (or indeed whether it can be implemented or not).
In my model I have a ...
0
votes
0
answers
442
views
EF Core Code first - relationship already being used
I'm still new to the .NET especially ef core. I am having trouble defining the relationship between the entities using code first approach with existing database. I develop this using Visual Studio ...
2
votes
0
answers
552
views
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 ...
1
vote
1
answer
1k
views
DbSet<T>.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; }
...
0
votes
0
answers
221
views
How to add relationships from the IdentityUser class in ASP.NET Core 3.1 Identity? (Code First)
I have a Asp.Net Core MVC 3.1 project. I want to join appointment and patient tables with code first technique however the foreign key column is null.
My Patient Class;
public class Patient : ...
0
votes
0
answers
134
views
Entity Framework MVC Code First BIND doesn't work for children entities inside EDIT action
I am using ASP Core Web Application, MVC, Code First, with MySQL db.
Here is the structure of my db:
Here is code for those 2 models/classes:
=====This code is for 2nd EmployeeDate Table (Child)=====
...
-1
votes
1
answer
903
views
Error while remove migration and update database entity framework core Exception while reading from stream
I am working in dotnet core web api using restful service with entity framework code first approach. I am running one migration and when I run the migration using add-migration command then I get ...
4
votes
1
answer
2k
views
How to make Entity Framework Core create a foreign key constraint that is not enforced
I'm using code-first with EF Core 3.1.2
I have established the following two-way one-to-one relationship in the OnModelCreating method of my DbContext.
modelBuilder.Entity<Inspection>()
....
1
vote
1
answer
1k
views
Shopping cart models design with Microsoft Entity Framework Core
I am new to Entity Framework Core. In my shopping cart models design, I have a little confusion in designing my model classes using Entity Framework Core.
I have assign collection of address to user ...
2
votes
1
answer
232
views
ASP.NET Core Entity Framework code-to-database scaffolding not recognizing Id property or [Key] annotation
I'm trying to scaffold out a razor page set for my Ticket class and I'm getting an error when Entity Framework tries to create the database:
My understanding is that if you have a property "Id" it ...
1
vote
0
answers
977
views
No mapping to a relational type can be found for property 'Identity.User.LockoutEnd' with the CLR type 'Nullable<DateTimeOffset>'
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 ...
0
votes
1
answer
155
views
EF Core navigation property without relations(foreign-key)
I have three classes
public class Country
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public byte CountryID { get; set; }
public byte OfficialLangID { get; set;...
0
votes
1
answer
165
views
EF6 Table Splitting and exception "A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: 'Id'."
For some time I've been following the "First Class Collections" rule from Object Calisthenics in my domain design. In order to avoid creating a useless "Collection" table though, I use the table ...
0
votes
2
answers
884
views
How to define a navigation property via Entity Framework code first approach
I have the following class that I want to use as my data context in Entity Framework:
public class AggregateRecord : IAggregateRecord
{
[Key]
public int AggregateRecordID { ...
0
votes
1
answer
1k
views
Mapping inheritance structure in Entity Framework Core to Postgres - Conflicting Error Messages
I have a number of inheritance hierarchies in my model. I'm using Entity Framework Core 3.1.2 with a Postgres database. Code First. I am trying to create a migration to generate my database tables.
I ...
1
vote
1
answer
849
views
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 ...
2
votes
0
answers
314
views
How would someone generate documentation from an Entity Framework code first mapping context?
I would like to generate a document from the Entity Framework code-first context class. The documentation would generate an object reference model and how it is mapped to the database. How would one ...
0
votes
2
answers
483
views
Create one to many and many to one mapping between two tables in entity framework 6 code first approach
I want to create below two tables using Entity Framework 6 code first approach. I can use attribute notation or fluent API or combination of both. Mainly I want to know how to create the mappings ...
0
votes
0
answers
67
views
I have one entity, i need to add property of entity type
**public class Ticket : BaseEntity
{
public TicketType TicketType { get; set; }
}
public class TicketType : AuxiliaryInfoBaseEntity
{
public string Description ...
0
votes
1
answer
280
views
Same Table Many-To-Many Connection EF CodeFirst .net Core
Hi i have a model class like
public class Individual : EntityBase
{
public Individual()
{
RelatedIndividuals = new HashSet<RelatedIndividual>();
}
public string ...
1
vote
0
answers
367
views
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 ...
3
votes
2
answers
773
views
getting an error if mapping is not there with EF core code first
Hi all i have model sections like this below
public class Sections
{
public int SectionId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
...
0
votes
1
answer
329
views
IndexBuilder and ForNpgsqlHasComment
Why NpgsqlEntityTypeBuilderExtensions and NpgsqlPropertyBuilderExtensions has ForNpgsqlHasComment method to set Comment, but NpgsqlIndexBuilderExtensions doesn't. How to set Comment for Index in ...
0
votes
1
answer
261
views
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 ...
1
vote
1
answer
911
views
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
--------------------------------...
3
votes
1
answer
4k
views
EF Core Deleting related entities on One To One relationship
I have a one to one relationship set up on ef core. When i try to delete Article
entity I need to cascade MediPlan since it is one to one relationship. When I Delete Article, MediaPlan is not getting ...
1
vote
0
answers
220
views
How to load only IDs when use many-to-many relationship in Entity Framework?
I have the following models:
class Item
{
public ICollection<string> GroupIds { get; set; }
// Introduced for EF only
public ICollection<Group> Groups { get; set; }
}
class ...
1
vote
2
answers
1k
views
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 ...
1
vote
1
answer
1k
views
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 ...
2
votes
3
answers
10k
views
EF Core - error with duplicated key while adding data with unique index
I'm trying to add data to the database using EF Core, but I cannot overcome duplicate key error: Cannot insert duplicate key row in object 'dbo.Stocks' with unique index 'IX_Stocks_Name'. The ...
0
votes
1
answer
833
views
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-...
0
votes
2
answers
212
views
Mapping to model
How do I map join table data to a model in the code first approach with entity? I'd like to fetch the user info belonging to the chat message when i fetch chat messages. I'm getting the error
...
0
votes
3
answers
2k
views
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; }
...
0
votes
1
answer
38
views
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 ...
1
vote
1
answer
1k
views
ef core code first generic inheritance mapping
All Positions have a Location (Many-to-1).
Different Location types have different Position types
Model:
public abstract class Location
{
public int Id { get; set; }
public string Name { ...
0
votes
1
answer
518
views
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 ...
0
votes
1
answer
610
views
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 ...
3
votes
2
answers
5k
views
It is possible to query a NotMapped property?
i'm working with EF6 code first, and i used this answer to map a List<stirng> in my entitie.
This is my class
[Key]
public string SubRubro { get; set; }
[Column]
...