AddOrUpdate does not modify children

.net c# entity-framework entity-framework-6

Question

My seed method uses AddOrUpdate to keep my permissions current, but because the code below updates an existing role rather than establishing one, any new permissions I make are not being added to the role. Why am I misusing this?

foreach (KeyValuePair<string, string[]> s in new Dictionary<string, string[]>{
                {"Superuser", context.Permissions.Select<Permission, string>(p=>p.Name).ToArray()},

            })
            {
                Role r = new Role();
                r.Name = s.Key;
                r.Permissions = new List<Permission>();
                foreach (string p in s.Value)
                    r.Permissions.Add(context.Permissions.Where(per => per.Name == p).First());

                context.Roles.AddOrUpdate(i => i.Name, r);
            }

context.SaveChanges();
1
3
4/14/2014 6:44:56 PM

Accepted Answer

ZZZ_tmp
8
4/15/2014 10:27:05 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow