Reputation: 708
In my project I want Log some Event for each Table like below events :
CreatedOn, CreatdBy,IsDeleted,DeletedBy,DeletedOn
for do this I create a ComplexType like this :
[ComplexType]
public class Log
{
public DateTime CreatedOn { get; set; }
public User CreatedBy { get; set; }
public Guid CreatorId { get; set; }
public bool IsDeleted { get; set; }
public User DeletedBy { get; set; }
public Guid? DeletedUserId { get; set; }
}
}
and use in another Table like this :
public class StoreMaster
{
//some fields
public virtual Log Log { get; set; }
}
and I have this Fluent like this :
HasRequired(row => row.Log.CreatedBy).WithMany(row => row.StoreMasters).HasForeignKey(row => row.Log.CreatorId).WillCascadeOnDelete();
when run Project I getting this error :
The expression 'row => row.Log.CreatedBy' is not a valid property expression. The expression should represent a property: C#: 't => t.MyProperty' VB.Net: 'Function(t) t.MyProperty'.
Upvotes: 1
Views: 36
Reputation: 39386
I'm afraid what you are trying to achieve is not possible. First thing is complex type can only contain primitives properties, so you can't declare navigation properties there. Second thing is the scalar properties you define in your complex type can't be used in the definition of a relationship.The parent object where you declare your complex type as property is the only who can manage it.
Upvotes: 1