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
().Property ("CreatedDate"); - modelBuilder.Entity
().Property ("ModifiedDate"); - modelBuilder.Entity
().Property ("DeletedDate"); - }
-
Also try this
- protected override void OnModelCreating(ModelBuilder modelBuilder) {
- modelBuilder.Entity
().Ignore(x => x.DeletedDate); - modelBuilder.Entity
().Ignore(x => x.IsDeleted); - modelBuilder.Entity
().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

Laxmidhar SahooPosted Jul 4, 2020, 3:02 AM
Ankit YadavPosted Jul 4, 2020, 2:41 AM
Laxmidhar SahooPosted Jul 4, 2020, 1:43 AM
Farhan AhmedPosted Jul 3, 2020, 11:29 AM