efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Shadow Property - ChangeTracker Modified State

Open CharlesToniolo opened this issue 10 years ago • 0 comments

Hello,

I'm having a strange behavior with a shadow property and i don't know if it's a bug or not. I was able to reproduce it in the dev branch.

Given these classes:

namespace Microsoft.EntityFrameworkCore.FunctionalTests.TestModels.Northwind
{
    public class ExtraValue
    {
        public string ID { get; set; }
        public string Description { get; set; }
    }
}

namespace Microsoft.EntityFrameworkCore.FunctionalTests.TestModels.Northwind
{

    public class Order
    {
        //public string ExtraValueID { get; set; } Shadow Property
        public ExtraValue ExtraValue { get; set; }

        public int OrderID { get; set; }
        public string CustomerID { get; set; }
        public int? EmployeeID { get; set; }
        ......
     }
}

I would like to have a Shadow Property called ExtraValueID to be the foreign key to the table ExtraValue. Entity framework is automatically creating this Shadow Property but when i select the root entity with AsNoTracking and Update the entity without changing anything like this:

var order = context.Orders.AsNoTracking()
   .Include(o => o.ExtraValue)
   .Where(o => o.OrderID.Equals(10248))
   .FirstOrDefault();

context.Update(order);

The Shadow Property context.Entry(order).Property("ExtraValueID") is being marked as modified with originalValue=null. I think that this property should not be marked as modified. If i create the property ExtraValueID inside the class Order, it works.

Thanks

CharlesToniolo avatar Feb 03 '16 17:02 CharlesToniolo