我在表上没有身份列,我不需要名为CountryID的同伴的身份。我将来自客户请求的CountryID值传递给CountryId列作为主键。一旦执行存储过程,我将得到上述错误,因为“表不具有标识属性。无法执行SET操作”。如何插入记录而不会出现此错误?
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int CountryID { get; set; }
public string CountryName { get; set; }
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int LanguageId { get; set; }
var result = await tDBContext.Query<SpResponseMessage>().FromSql("exec sp_synchCountry " +
"@p0, @p1, @p2",
objCountry.CountryID,
objCountry.CountryName
objCountry.LanguageId).SingleOrDefaultAsync();
答案 0 :(得分:1)
如果要将多个属性配置为实体的键(称为复合键)。只能使用Fluent API配置组合键-约定永远不会设置组合键,并且您不能使用数据注释来配置组合键。
<div>
<label><input type="checkbox" name="actorCheckbox" value="BradPitt"> Brad Pitt </label>
<label><input type="checkbox" name="actorCheckbox" value="AngelinaJolie"> Angelina Jolie </label>
</div>
<div class="movie BradPitt AngelinaJolie">Mr and Mrs Smith</div>
<div class="movie BradPitt">Something with only Pitt in it</div>
<div class="movie AngelinaJolie">Something with only Angelina in it</div>
<div class="movie Joker">Something with clowns</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<script>
$(document).ready(function() {
var showElements = function() {
$('.movie').hide(); // hide all .movie elements
$('input[name=actorCheckbox]:checked').each(function() {
$('.movie.' + $(this).val()).show();
});
}
$("input[type=checkbox]").on("change", showElements);
});
</script>
参考:https://docs.microsoft.com/en-us/ef/core/modeling/keys#fluent-api