I have properties in my Model like
- public class Test{
- public int Id{ get; set; }
- public string Title { get; set; }
- public DateTime? CreatedDate { get; set; }
- public DateTime? ModifiedDate { get; set; }
- public DateTime? DeletedDate { get; set; }
- }
Here, I am using this Test class for creating Table in Database using Migration, Now the table is created successfully but the problem is when i want do any operation using stored procedure which is like " Select Title from Test where Id=1" ,When i run the this i am facing error like this
The required column 'CreatedDate' was not present in the results of a 'FromSql' operation"
I tried
- NotMapped Attribute it works fine but when i add another migration the NotMapped properties gets Dropped from the database after updating the database
- Also use Shadow properties and Ignore properties like
-
- protected override void OnModelCreating(ModelBuilder modelBuilder)
- {
- modelBuilder.Entity<Test>().Property<DateTime?>("CreatedDate");
- modelBuilder.Entity<Test>().Property<DateTime?>("ModifiedDate");
- modelBuilder.Entity<Test>().Property<DateTime?>("DeletedDate");
- }
-
Also try this
- protected override void OnModelCreating(ModelBuilder modelBuilder) {
- modelBuilder.Entity<Test>().Ignore(x => x.DeletedDate);
- modelBuilder.Entity<Test>().Ignore(x => x.IsDeleted);
- modelBuilder.Entity<Test>().Ignore(x => x.ModifiedDate); }
But the issue remains the same ,
So the issue is i want to ignore the CreateDate, ModifiedDated, DeletedDated property while performing DB operation and also not want to drop these columns from Database when i add and update new migration. Can anyone guide me what i need to do to resolve this issue.
Reference link: https://stackoverflow.com/questions/47057856/ignore-properties-in-data-model-while-keeping-them-in-ef-core-migrations