A navigation property is an optional property on an entity type that allows for navigation from one end of an association to the other end. Unlike other properties, navigation properties do not carry data. A navigation property definition includes the following: A name.
Navigation properties in the Entity Framework provide a way to navigate an association between two entity types.
If you define your navigation property virtual , Entity Framework will at runtime create a new class (dynamic proxy) derived from your class and uses it instead of your original class. This new dynamically created class contains logic to load the navigation property when accessed for the first time.
I have the next enitities:
public class MyEntity
{
public virtual int Id { get; set; }
public virtual MySecondEntity SecondEntity { get; set; }
}
public class MySecondEntity
{
public virtual int Id { get; set; }
...
some properties here
...
}
I don't want to create MySecondEntityID property in order to have clean model.
I need to set myEntity.MySecondEntity by its Id, but I don't want to request MySecondEntity from DB.
Is it possible to do it without creating MyEntity.MySecondEntityID property and without loading the whole MySecondEntity object or even without any db requests?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With