Linked Questions
22 questions linked to/from Why use 'virtual' for class properties in Entity Framework model definitions?
0 votes
2 answers
2k views
Regarding the use virtual keyword for a property [duplicate]
I have seen people use the virtual keyword for property like this: public class Client { public virtual int? Id { get; set; } public virtual string Name { get; set; } public virtual ...
0 votes
3 answers
236 views
Using virtual in C# [duplicate]
What is the purpose of virtual in C#? What is the proper way and reason to use it? For example, public virtual ICollection<Order> Orders { get; set; } in defining a collection orders in a ...
254 votes
2 answers
107k views
What effect(s) can the virtual keyword have in Entity Framework 4.1 POCO Code First?
Does the virtual keyword has an effect when used on the properties in EF Code First?. Can someone describe all of its ramifications in different situations? For instance, I know it can control lazy ...
58 votes
1 answer
28k views
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; ...
7 votes
3 answers
18k views
Entity Framework returns null for Include properties
I got 3 entities(tables) that have many to many connections: public class AccUserRole { public long Id { get; set; } public string RoleName { get; set; } public List<AccAdGroup> ...
3 votes
2 answers
2k views
using a class name in another class property.? [duplicate]
I am pretty new to C#. I have two classes a Movie class and a Genre class.I cant understand the property "public virtual Genre Genre" Could someone explain me this? Following are the two classes ...
2 votes
1 answer
6k views
Using Virtual on properties of a model
I'm following a tutorial series about MVC4 on PluralSight and the presenter sets all of the properties of all of his models as virtual. I haven't seen others do this and I was wondering if it is the ...
0 votes
1 answer
3k views
Virtual keyword in Entity Framework properties
public class Student { public int StudentId; public string StudentName; public int CourseId; public virtual Course Courses { get; set; } } public class Course { public int ...
4 votes
1 answer
997 views
How to update ApplicationUser with new fields in asp.net webforms using local authentication?
I have added 3 new fields to my Register.aspx template (FirstName, LastName, BuisnessName). I have updated the database schema but when I register a new user, the user is created but the new fields ...
1 vote
1 answer
2k views
virtual DbSet<> in the current EF Core (7 or 8)
EDIT: This question has been closed because someone thought it is a duplicate for another question on SO. It is not. The duplicate question, and all of the (old) docs I've found, deal with adding ...
0 votes
1 answer
1k views
Entity Framework. Field value is null after save and read
I have a problem with EF. May I misunderstand something.... So i have a simple model: public class Image { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } ...
2 votes
1 answer
618 views
Using Virtual on navigation properties
I want to know when we use the key word virtual with navigation properties (I learnt it's for lazy loading) but I'm reading a tutorial in https://docs.asp.net/en/latest/data/ef-mvc/intro.html that ...
0 votes
1 answer
588 views
ASP.Net Core related models field required error
I have two models which are related like following: public class Context { [Key] public long ContextId { get; set; } [Required] public string Role { get; set; } ...
0 votes
1 answer
237 views
Using Entity Framework queries to get all entries on a table related to other 2 tables
Consider this model. Basically what I'm trying to do is obtaining every door in the table 'doors' such that there exists a corresponding entry in the table 'doors_to_devices' with a given device_id. ...
0 votes
2 answers
170 views
Object property is null after taking data from DB. Entity Framework
I have a DBContext that is initializing through DropCreateDatabaseAlways class. In the Seed method I have this code: base.Seed(context); var c1 = new Company { Name = "Samsung"...