Questions tagged [ef-fluent-api]

A way to configure Entity Framework beyond its conventions with a method chaining API

Use the tag for questions that ask about:

  • Model-wide settings
  • Property mapping
  • Type mapping
  • Relationships

The EF-Fluent API can be used in both c# and VB.NET.

The MSDN documentation

833 questions
2
votes
2 answers

EF Core FK Constraint on Alternate Key

Hi I have an entity as below public class SalaryTransactionAudit { public long SalaryTransactionAuditId { get; set; } public Guid TransactionBatchId { get; set; } public DateTime UploadedDate { get; set; } public string…
Alan B
  • 2,219
  • 4
  • 32
  • 62
2
votes
2 answers

EF6 One-To-Many Relationship with 2 tables in Legacy SQL Database

I am trying to configure a One-To-Many relationship where the second table has a reference to the first table. The tables are in an existing legacy Sql Server database. I have a Customer table and a CustomerBranches table like so: I have a POCO…
2
votes
1 answer

Where is metadataworkspace in Entity Framework core?

I am trying to read the custom attributes using reflection set by Fluent API in EntityFramework Core. I did a bit of research and found that MetadataWorkspace can be helpful as suggested in these links: Link 1, Link 2. All these solutions are on…
2
votes
2 answers

Writing One to one relationship using Fluent API

How to write a one-to-one--or-zero relationship using fluent api? Can someone help me out correct what i have written. I am not sure if its correct. The scenario : One Student Can have one or zero Address. Student Model public int Id{ get; set;…
Illep
  • 16,375
  • 46
  • 171
  • 302
2
votes
1 answer

EF one to many on part of composite primary key

I have three layers of tables in an existing database and I'm trying to include the bottom level records when I get the middle level data... This should be a one to many relationship - for shipment x with product y there are z analysis…
goneos
  • 319
  • 2
  • 4
  • 16
2
votes
1 answer

How to configure muliple relationships in fluent api using code first?

I am receiving following exception while running the code An object of type 'System.Collections.Generic.HashSet`1[[SolutionName.ProjectName.Contract, SolutionName.ProjectName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' cannot be…
2
votes
2 answers

Multiple one-to-one relationship with two independent tables and one dependent

I have read a lot of related questions about this topic but none of them seemed to address my problem, so please bear with me. I am new to EF and trying to establish the following relationship, in ASP .NET MVC, using EF6: I need to have two…
Sfmar
  • 159
  • 1
  • 13
2
votes
2 answers

EF Core - Define custom column mapping strategy for all properties

By convention, each property will be set up to map to a column with the same name as the property. If I want to change the default mapping strategy, I can do it by using either Fluent API or Data Annotation. But, I want to set a custom mapping…
2
votes
2 answers

One-To-One relationship with FK distinct from PK

I have 2 tables in database: ReceivedGoods and ReceivedGoodsProperties ReceivedGoods contains ReceivingId as PK and must have its extending data in ReceivedGoodsProperties which contains ReceivingId as FK referencing to the ReceivedGoods's…
esgaldir
  • 823
  • 9
  • 11
2
votes
1 answer

EF CORE - Fluent API - cascading delete restrict to on table

The model: public class AccountUser { public long AccountUserId { get; set; } ... public long UserPermissionGroupId { get; set; } public UserPermissionGroup UserPermissionGroup { get; set; } } public class UserPermissionGroup { …
ferdinand
  • 970
  • 1
  • 7
  • 14
2
votes
1 answer

Can I mix Fluent API with Annotations Attributes in EF 6?

I have convention to put [Key] as an Annotation Attribute in Entity and rest of the configuration into FluentAPI (ForeignKeys mostly). I worked great, but then I found out that EF6 has this "magic conventions", that will create PK or FK if the name…
Ish Thomas
  • 2,270
  • 2
  • 27
  • 57
2
votes
1 answer

When declaring relationship is not necessary in Entity Framework 6?

In EF6 we have two ways to declare relationship between two tables: Annotations Attributes Fluent API Today (by accident) I removed one relationship between two tables and everything kept working well. I was very surprised because there was no way…
2
votes
1 answer

Procedure Or Function SpAddDepartment Has Too Many Arguments Specified

Problem I get an error Procedure or function spAddDepartment has too many arguments specified How to solve it? Details: when inserting data into table department using stored procedure spAddDepartment using fluent api in ASP.NET MVC 5, I get that…
2
votes
2 answers

EF6 One To Many Fluent Mapping

In EF6, given that these two approaches seem to function identically, are there any advantages in choosing one approach over the other? modelBuilder.Entity() .HasRequired(p => p.CurrentTeam) .WithMany(t => t.Players) …
Joe
  • 5,389
  • 7
  • 41
  • 63
2
votes
0 answers

Resolve duplicate fields when inheriting IdentityUser

Help! I am migrating an old ADO application to Entity and Identity Framework's. I have a USERS table, which my analyst does not allow me to change in anything. It has relationships with other context tables and this blessed ID column. To Use…