在下面的代码中,我需要在ParentInfoAddProperties.ParentQuestionAnswersId上设置一个外键constrant,以便它依赖于ParentQuestionAnswers.Id(这是一个主键).我试图使用数据注释,但实体框架6想要在我的ParentQuestionAnswers表中创建一个新的外键列,该列引用ParentInfoAddProperties.Id列而不是ParentInfoAddProperties.ParentQuestionAnswersId列.我不希望Entity Framework创建新的外键列.
如果有人能够解释我应该指定哪些数据注释或(如果需要)流畅的映射来实现所需的外键实例,我将不胜感激.提前致谢.
namespace Project.Domain.Entities
{
public class ParentQuestionAnswers
{
public ParentQuestionAnswers()
{
ParentInfoAddProperties = new ParentInfoAddProperties();
}
[Required]
public int Id { get; set; }
[Required]
public int UserId { get; set; }
public ParentInfoAddProperties ParentInfoAddProperties { get; set; }
}
public class ParentInfoAddProperties
{
[Required]
public int Id { get; set; }
[Required]
public int ParentQuestionAnswersId { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud) c# foreign-keys data-annotations ef-code-first entity-framework-6
我需要为MVC TextBox HTML帮助器分配多个类,因此它的功能与为HTML元素分配多个类时的功能相同.
即: <div class="class1, class2"></div>
以下不能正常工作:
@Html.TextBoxFor(x => x.Name, new { @class = "class1, class2" })
Run Code Online (Sandbox Code Playgroud)
注意:我需要将两个类名添加到单个元素中,以便触发不同的jQuery函数.任何建议将不胜感激.