I think that what you are trying to do is impossible in EF. Maybe I am wrong. I did it with implementing common properties by defining interfaces:
public interface ICreationInfo
{
DateTime CreationDate { get; set; }
User CreatedBy { get; set; }
EntityReference<User> CreatedByReference { get; set; }
}
public interface ILastModificationInfo
{
DateTime LastModificationDate { get; set; }
User LastModificationBy { get; set; }
EntityReference<User> LastModificationByReference { get; set; }
}
Then I defined T4 template to have it in every entity class:
<#@ template language="C#" #>
<#@ output extension="cs" #>
<#@ import namespace="System.Collections.Generic" #>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Web;
<#
String[] classNames = new String[] {"User","Project","Group","GroupUser","OperationSystem","TaskType","Priority","Severity","Status","Version","Platform","Task","TaskUser","Attachment","Comment","Setting","CustomField"};
List<String> classWithoutModificationInfo = new List<String>();
classWithoutModificationInfo.Add("GroupUser");
classWithoutModificationInfo.Add("TaskUser");
classWithoutModificationInfo.Add("Attachment");
#>
namespace CamelTrap.Models
{
<# foreach(String className in classNames) { #>
public partial class <#= className #> : IBasicEntityInfo, ICreationInfo <#= (!classWithoutModificationInfo.Contains(className))?",ILastModificationInfo":"" #>
{
}
<# } #>
}
This generates code:
public partial class User : IBasicEntityInfo, ICreationInfo, ILastModificationInfo
{
}
public partial class Project : IBasicEntityInfo, ICreationInfo, ILastModificationInfo
{
}
public partial class Group : IBasicEntityInfo, ICreationInfo, ILastModificationInfo
{
}
When I want to access basic properties, I check interface.