Questions tagged [navigation-properties]

Navigation Properties are used within The Entity Framework to Navigate to relations of a table. These relations are made by foreign keys. The Navigation Properties can be loaded in many different ways by using Includes, LazyLoading and explicit loading.

397 questions
121
votes
2 answers

Entity Framework - Add Navigation Property Manually

I generated an Entity Framework Model (4.0) from my database. I did not design the database and do not have any control over the schema, but there are a few tables that do not have foreign key constraints defined, but there is an implicit…
Dismissile
  • 32,564
  • 38
  • 174
  • 263
103
votes
5 answers

navigation property should be virtual - not required in ef core?

As I remember in EF navigation property should be virtual: public class Blog { public int BlogId { get; set; } public string Name { get; set; } public string Url { get; set; } public string Tags { get; set; } public…
80
votes
6 answers

EF codefirst : Should I initialize navigation properties?

I had seen some books(e.g programming entity framework code first Julia Lerman) define their domain classes (POCO) with no initialization of the navigation properties like: public class User { public int Id { get; set; } public string…
55
votes
1 answer

Why Navigation Properties are virtual by default in EF

I have following POCO class being used in EF 6.x. My question: Why is the navigation property of 'Posts' under 'Blog' entity declared as virtual? public class Blog { public int BlogId { get; set; } public string Name { get; set; } …
Sunil
  • 20,653
  • 28
  • 112
  • 197
21
votes
3 answers

Entity Framework (Database-First) multiple relations to same table naming conventions control

Let's suppose that we have this situation: Tables in database: Country (id, country_name), Person (id, login), CountryManager (id_country, id_person), CountryStakeholder (id_country, id_person) If we had to create the model from the database, using…
17
votes
4 answers

Entity Framework - Include / Reference / Collection

I was wondering why there are separate methods for populating navigation properties. If I work on an entire set, i can call Include on either a property or a collection. However, if I work on a single entity, there are two separate methods to call…
Simon
  • 9,197
  • 13
  • 72
  • 115
17
votes
2 answers

How to Model Entity Framework Entity/Mapping With Only One-Way Navigation

Using EF 5, Code First. I'd like to model my entities such that the navigation properties only exist on one side of the relationship. So if I have a table Widget, and a table WidgetType: public class Widget { public int Id { get; set; } …
16
votes
4 answers

OData and WebAPI: Navigation property not present on model

I'm trying to put together a simple toy project using Entity Framework, WebAPI, OData, and an Angular client. Everything is working fine, except the navigation property that I have put on one of my models doesn't seem to be working. When I call my…
MWinstead
  • 1,265
  • 6
  • 12
  • 27
14
votes
1 answer

EF Core Collection Load .. of a Collection

Using EF Core 1.1.0 I have a model that has collections that themselves have collections. public class A { public string Ay {get;set;} public List Bees {get;set;} } public class B { public string Be {get;set;} public List Seas…
imukai
  • 638
  • 1
  • 7
  • 17
13
votes
2 answers

Entity Framework Core: private or protected navigation properties

Is it somehow possible to define navigation properties in EFCore with private or protected access level to make this kind of code work: class Model { public int Id { get; set; } virtual protected ICollection childs { get; set; } …
12
votes
3 answers

Using Automapper, mapping DTOs back to Entity Framework including referenced entities

I've got POCO domain entities that are persisted using Entity Framework 5. They are obtained from the DbContext using a repository pattern and are exposed to a RESTful MVC WebApi application through a UoW pattern. The POCO entities are proxies and…
10
votes
1 answer

Writing LINQ queries. Joins VS navigational properties

I am trying gain more understanding of Linq queries and Entity Framework (4.1). Please take a look at following two queries. Both queries returns car type name (CarType.Name) In first query I used join and ignored navigational property CarType from…
bobetko
  • 5,019
  • 14
  • 58
  • 85
9
votes
1 answer

Can many-to-many relationships in EF Core 5.0 be configured keeping just one navigation property (on one side)?

I've configured my DbContext (EF Core 5.0) with the following code: protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity() .HasMany(p => p.Roles) .WithMany(p => p.Users) …
SuperJMN
  • 13,110
  • 16
  • 86
  • 185
9
votes
1 answer

Can I lazy load a navigation property by delegating to a stored procedure in EF?

I have the following customer class: public class Customer { public long Id { get; set; } public virtual ICollection Orders { get; set; } } My database has Customers and Orders tables, but no foreign key relationships. Orders for a…
dommer
  • 19,610
  • 14
  • 75
  • 137
9
votes
1 answer

How to update an entity's navigation properties in Entity Framework

In ASP .NET MVC 3 with Entity Framework, I have a domain object which has a navigation property referencing another objects, as follows: public class Person { public String Name {get;set;} public Guid CompanyID{get;set;} …
1
2 3
26 27