foreach语句无法对类型为变量的变量进行操作 [英] foreach statement cannot operate on variables of type
问题描述
朋友 !
我有2个 表 学生 和 HistoricoEscolar ,我需要 将 记录 插入表中 要做 HistoricoEscolar 还 更新 学生
表 .
我在表中 下面的代码中添加了 HistoricoEscolars
Friends!
I have 2 tables Student and HistoricoEscolar, I needthat whena recordis insertedin the tabledoHistoricoEscolaralsoupdatetheStudent
table.
I addedthe code belowin TableHistoricoEscolars
部分无效的HistoricoEscolars_Inserting(HistoricoEscolar实体)
{
foreach(实体中的Aluno权限.AlunoNome)
{
detalhes.HoraAulaInio =实体.HoraInicioAula;
}
partial void HistoricoEscolars_Inserting(HistoricoEscolar entity)
{
foreach (Aluno detalhes in entity.AlunoNome)
{
detalhes.HoraAulaInio = entity.HoraInicioAula;
}
我遵循了 一个例子 我在上找到了
网站 MSND , 但是 是
错误 , 以下消息 显示 :
foreach 声明 不能 操作
上 变量 类型 ' LinghtSwitchApplication.Aluno '
因为 ' LightSwitchApplication.Aluno '没有
包含 a 公共 定义
GetEnumerator ' .
您想 帮助朋友 解决
这个问题 .
I followed an example I found on the
site MSND, however is
error, the following message is displayed:
foreach statement can not operate
on variables of type 'LinghtSwitchApplication.Aluno'
because 'LightSwitchApplication.Aluno' does not
contain a public definition
for 'GetEnumerator'.
Would you like to help friends to solve
this problem.
推荐答案
实体上的AlunoNome属性不是集合属性,而是标量.这就是为什么您不能迭代它的原因.确保涉及此属性的关系是正确的;您可能有一对多关系,但相反 您真正想要的东西.
The AlunoNome property on the entity is not a collection property but is scalar. That's why you cannot iterate it. Make sure that your relationship involving this property is correct; you likely have a One-To-Many relationship, but have it the reverse of what you actually want.
这篇关于foreach语句无法对类型为变量的变量进行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!