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
0
votes
0 answers

Add C#-calculated columns to tables?

I'm building an Entity Framework data context for a pre-existing application. As this application has a nice clean set of POCOs that define the domain model, I opted to use EF's Code First to generate the database from these classes so that we don't…
anaximander
  • 7,083
  • 3
  • 44
  • 62
0
votes
1 answer

How to configure one to one optional relationship with FK

For a restriction of our architecture, the Id property can not be changed! I have an employee class: public class Employee { public virtual int Id {get; Set; } public virtual int Matricula {get; Set; } } And a user class (System User)…
ridermansb
  • 10,779
  • 24
  • 115
  • 226
0
votes
0 answers

Include causes OutOfMemoryException

I have a very strange problem when using Entity Framework with Code First approach. I have disabled lazy loading and are using include statements when I need. Unfortunately I cannot show you the code, but will try to explain as detailed I can. I…
0
votes
1 answer

How can I expose the Join table?

I'm trying to follow this idea from Jimmy Bogard on avoiding Many-to-Many-Mappings in ORMs Given this setup I want to be able to also directly expose the 'Join' object in the relationship. Objects User Role UserRole (association…
ctrlShiftBryan
  • 27,092
  • 26
  • 73
  • 78
0
votes
2 answers

Fluent mapping inheritance

I have an issue I don't know the best solution for. Hopefully someone here can help =) What I'm trying to solve: We have to type of users in a system, person and organization. I want to have a shared login table for the two (ie the user probably…
Zaphod
  • 1,412
  • 2
  • 13
  • 27
0
votes
3 answers

How do I create a table that has a composite key each member of which is a foreign key member to other tables

I am trying to do code first with annotations (for the first time) on an MVC project. I have created the following POCOs. [Table("Customers")] public partial class Customer { public int Id { get; set; } [Required] [DisplayName("First…
0
votes
1 answer

Add-Migration error: Schema specified is not valid

I can not create a new migration Add-Migration Testing Package version Microsoft.AspNet.WebApi -> 5.0.0-beta1-130515 Microsoft.AspNet.WebApi.Client -> 5.0.0-beta1-130515 Microsoft.AspNet.WebApi.Core -> …
-1
votes
1 answer

EF Core: combining 2 configuration extension method calls in one extension method call

I am using EF Core Code-First Approach to configure/map an entity class named Student to SQL Server table named Student. The Student entity model class has a string column named Name that will be mapped to a SQL Server column named "Name" that…
-1
votes
1 answer

How to configure, map One to One Relationship in EF Core

As a student I have to design my first WebApi using .Net Core. I have been searching for two days, and haven't found an answer that solves my problem. Maybe because i'm a beginner. I have following classes: public class Boat { public int BoatId…
Segher
  • 3
  • 2
-1
votes
1 answer

ASP.NET Core - the DELETE statement conflicted with the REFERENCE constraint . The conflict occurred in database

I'm trying to solve this problem for hours. I believe it's some kind of relationship problem. I get this error: The DELETE statement conflicted with the REFERENCE constraint "FK_NoteTag _Notes_NoteId". The conflict occurred in database "db", table…
-1
votes
1 answer

EF6 Database-First: Multiplicity constraint violated. The role '...' of the relationship '...' has multiplicity 1 or 0..1

I'm getting the error Multiplicity constraint violated. The role 'CollectionSite_CollectionSiteOption_Target' of the relationship 'DatabaseRefreshRecovery.Data.CollectionSite_CollectionSiteOption' has multiplicity 1 or 0..1. and I can't figure out…
cnotes
  • 247
  • 1
  • 4
  • 15
-1
votes
2 answers

Relation Many to Many EF6 Fluent API

I am developping an application using EF6 with Fluent API and I have an issue to manage Many-To-Many relationship. For some internal reasons the Join table has a specific format including 4 fields - Left Id (FK) - Right Id (FK) - StartDate…
-1
votes
1 answer

FluentValidation: how to simplify this code?

I'm using FluentValidation library to create validators like this: Please any one help me to simplify this part of code? private bool UniqueSimNo(string simNo) { MyContext _db = new MyContext(); Sim s = _db.Sims.Where(x =>…
-1
votes
1 answer

How define class via Code First in Entity Framework

I have class Plant with some attributes. public class Plant { public int Id { get; set; } // some attributes [Display(Name = "Благоприятные соседи")] public virtual List PositivePlants { get; set; } [Display(Name =…
-1
votes
1 answer

EntityFramework. Fluent Api. Invert mapping

I have the following classes: class Parent { public int ID; public Child Child1; public Child Child2; } class Child { public int ID; public string Data; } Using DbModelBuilder I have the following Fluent API…
Anatolyevich
  • 671
  • 5
  • 14
1 2 3
55
56