如何过滤swift 4的对象数组,然后删除(How to filter array of objects swift 4 then remove after)
我想避免出现此错误图像的错误
这是INDEX超出范围。 我试图通过一个数组循环,但是当我找到我想要删除的东西时,我将它删除,但数组的.count与for循环的迭代保持不变,我该如何解决这个问题?
这是运行时的控制台
test i:0 count: 3 test i:1 count: 3 test i:2 count: 2
然而,to:in
for i in stride(from: 0, to: count, by: 1)
仍然似乎是3 ...
有人可以告诉我如何过滤这个数组或循环并移除? 只要它工作,我不在乎它是什么
I want to avoid getting this error image of error
which is INDEX out of range. Im trying to loop through an array but when I find something I want to remove , I delete it yet the .count of the array remains the same for that iteration of the for loop , how can I fix this?
here is console when run
test i:0 count: 3 test i:1 count: 3 test i:2 count: 2
yet the to: in
for i in stride(from: 0, to: count, by: 1)
still seems to be 3...
Can Someone show me how to filter this array or loop through and remove? as long as it works i dont care what it is
原文:https://stackoverflow.com/questions/50119824
最满意答案
Unable to update the EntitySet because it has a DefiningQuery and no element exists in the element to support the current operation.
Make sure that your table has a primary key !
If not add the primary key and update the Entity Framework model and run again.
相关问答
更多-
不知道为什么会发生这种情况,但如果您还检查了db.dlc_Products的Local集合,则db.dlc_Products第一个SaveChanges() : foreach (var product in dlc_products.ToList()) { var dlc_product = db.dlc_Products.SingleOrDefault(p => p.name == product.name) ?? db.dlc_Products.Local.SingleOrDefa ...
-
确保您对此事务中的所有查询使用相同的ObjectContext实例。 Make sure that you are using the same instance of the ObjectContext for all the querys on this transaction.
-
要存储1.0,您需要将数字声明为 [N15] NUMERIC (2, 1) NULL, 或者只是不宣布精确度。 请参阅: https : //msdn.microsoft.com/en-AU/library/ms187746.aspx The problem was with the EDMX. Only changes in database does not make it work. Since EDMX does not updates itself with the changes in d ...
-
无法更新EntitySet,因为它具有DefiningQuery,并且元素中不存在元素以支持当前操作。 确保你的表有一个主键 ! 如果不添加主键并更新实体框架模型并再次运行。 资源: Unable to update the EntitySet because it has a DefiningQuery and no element exists in the element to support the current operation. Make sure that your table has a ...
-
如果您使用DbContext两个不同实例(您命名为db变量),那么当您在与实体跟踪的上下文不同的上下文中调用SaveChanges时,将不会保存任何内容。 您首先需要使用Attach方法。 db.customer_images.Attach(item); db.SaveChanges(); 不过,我认为你的情况你可以避免附加步骤,如果你重构一下你的代码,并且不使用实体本身的DbContext。 If you are using two different instances of the DbContex ...
-
EF:db.SaveChanges()vs dbTransaction.Commit(EF: db.SaveChanges() vs dbTransaction.Commit)[2023-08-21]
是的,如果您明确地将您的上下文封装在诸如.Net的TransactionScope之类的事务中,则可以在调用.SaveChanges()调用之后从实体中检索自动生成的ID,而无需提交该作用域事务。 using (var tx = new TransactionScope()) { using (var context = new MyDbContext()) { var newEntity = populateNewEntity(); context.MyEntities.Add ... -
ASP MVC5-Custom要求验证在db.savechanges失败(ASP MVC5-Custom requiredif validation failing at db.savechanges)[2023-04-22]
这是因为在浏览器级别(Javascript验证)触发的验证看到当选择No时,它会通过验证。 但是,在服务器端,EF正在执行相同的验证。 在保存之前检查并查看person1在服务器端的值:如果为空或是,那就是问题所在。 在这种情况下,我为我的视图(你拥有的那个)创建了一个模型,为我的ORM(EF)创建了一个模型。 在EF模型中,不要放置RequiredIf属性。 在保存之前将模型(用于视图)转换为模型(用于EF)并且一切都应该是好的。 That is because the validation fired ... -
您尚未提供模型,但在以下行中使用ref关键字: if (city.FromLat > city.ToLat) More.Swap(ref city.ToLat, ref city.FromLat); if (city.FromLng > city.ToLng) More.Swap(ref city.FromLng, ref city.ToLng); 清楚地表明FromLat , ToLat , FromLng和ToLng成员是字段 ,因此不映射到数据库列。 使它们成为属性并使用不同的代码进行交换(更长一点 ...
-
密码更改时,未加载复杂类型,因此在更新密码时db.savechanges()不起作用,因此如果加载复杂类型(在这种情况下为地址),问题就解决了 while password change the complex types were not loaded so while updating he password db.savechanges() didn't work so if you load the complex types(addresses in this case) the problem ...
-
mvc4 - db.SaveChanges() - 十进制值超出范围(mvc4 - db.SaveChanges() - decimal value out of range)[2023-05-14]
找到这两个线程之间的交易: 如何使用EntityFramework 4.1 CodeFirst阻止十进制值在保存时被截断为2个位置? EF Code First中的十进制精度和比例 具体应用此代码到我的: public class MyContext : DbContext { public DbSetMetrics { get; set; } protected override void OnModelCreating(DbModelBuilder modelBui ...