Entity framework 代码优先实体的业务规则放在哪里

Entity framework 代码优先实体的业务规则放在哪里,entity-framework,Entity Framework,我们在项目中首先使用MVP和实体框架代码。对于大多数基本函数,我们将使用DbContext,但我们希望围绕添加概要文件来包装一些逻辑。验证和其他一些规则 所以我们的目标被定义为通常的: public class Profile:BaseEntity { [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid ProfileId {get; set; } public strin

我们在项目中首先使用MVP和实体框架代码。对于大多数基本函数,我们将使用DbContext,但我们希望围绕添加概要文件来包装一些逻辑。验证和其他一些规则

所以我们的目标被定义为通常的:

public class Profile:BaseEntity
{
    [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]     
    public Guid ProfileId {get; set; }
    public string FirstName {get; set; }
    //....
}
我希望有一种方法可以这样调用:

var newProfile = new Profile
{
    FirstName = "John", 
    ...
}
newProfile.Insert();
// or 
_dbContext.Profile.Add(newProfile);
并调用我们的方法来执行我们的业务规则:

public bool AddProfile(Profile thisProfile)
{
    // Do our business
    return true; // or false if failed
}
我只是不确定把这种方法放在哪里最好。我可以将其添加到Profile.cs吗?我应该将其添加到DbContext类中吗


我不确定要搜索的最佳方式或最佳术语。

如果只在少数情况下需要,可以覆盖dbcontext的ValidateEntity方法

只有在调用SaveChanges()时,才会验证此选项