无法将类型"字符串"隐式转换为"System.Collections.Generic.ICollection<Fast.Models.Reviews>"


string updatedVotes = string.Empty;
updatedVotes = updatedVotes.Substring(0, updatedVotes.Length - 1);
db.Entry(sch).State = EntityState.Modified;
sch.Rates = updatedVotes;
db.SaveChanges();

但是由于你在上面看到的错误,代码无法编译,我还没有完全理解为什么。有人能帮忙吗?

updatedVotes是一个字符串,但是您试图将其分配给Rates(我假设它是Fast.Models.Reviews的集合)。

你有错误的类型。猫不能转换为狗,因此字符串不能转换为System.Collections.Generic.ICollection

错误消息大致告诉您发生了什么。在这一行:

sch.Rates = updatedVotes;

Rates是ICollection<Review>,而updatedVotes是string。不能将string分配给ICollection<Review>

相关内容

最新更新