当前位置: 首页>>代码示例>>C#>>正文


C# EntitySet.AddRange方法代码示例

本文整理汇总了C#中EntitySet.AddRange方法的典型用法代码示例。如果您正苦于以下问题:C# EntitySet.AddRange方法的具体用法?C# EntitySet.AddRange怎么用?C# EntitySet.AddRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EntitySet的用法示例。


在下文中一共展示了EntitySet.AddRange方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AgregarActividad

        public static object AgregarActividad(string actividadJSON, string preguntasJSON, string respuestasJSON)
        {
            Actividade actividad = JsonConvert.DeserializeObject<Actividade>(actividadJSON);
            List<Pregunta> preguntas = JsonConvert.DeserializeObject<List<Pregunta>>(preguntasJSON);
            List<Respuesta> respuestas = JsonConvert.DeserializeObject<List<Respuesta>>(respuestasJSON);

            foreach (Pregunta p in preguntas)
            {
                foreach (Respuesta r in respuestas)
                {
                    if (p.ID == r.FK_Pregunta)
                    {
                        p.Respuestas.Add(r);
                    }
                }
            }

            //Converting List to EntitySet
            var preguntasEntitySet = new EntitySet<Pregunta>();
            preguntasEntitySet.AddRange(preguntas);

            actividad.Preguntas = preguntasEntitySet;

            using (var dataContext = new OBJ_REDDataContext())
            {
                var actRepo = new Repository<Actividade>(dataContext);
                try
                {
                    actRepo.Insert(actividad);
                    dataContext.SubmitChanges();
                    return (new
                    {
                        valido = true,
                        mensaje = "Actividad guardada correctamente."
                    });
                }
                catch (Exception)
                {
                    return (new
                    {
                        valido = false,
                        mensaje = "Hubo un error al internar guardar la actividad."
                    });
                }
            }
        }
开发者ID:Chnxo,项目名称:OBJ_REDES,代码行数:46,代码来源:CrearActividad.cs

示例2: ListChanged_WithSource

        public void ListChanged_WithSource()
        {
            // When is ListChanged emitted?
            // It's not always when you think it would be.
            var people = new EntitySet<Person>();
            var events = new List<ListChangedEventArgs>();
            people.ListChanged += (o, e) => events.Add(e);

            // This is also true if Enumerable.Empty<Person>() is used here.
            people.SetSource(new[]{
                new Person { FirstName = "(", LastName = ")" },
            });
            AssertEqual(events);
            Assert.IsTrue(people.IsDeferred);

            // *Initial* Add()/AddRange() is ignored.
            people.Add(new Person { FirstName = "A", LastName = "B" });
            people.AddRange(new[]{
                new Person { FirstName = "1", LastName = "2" },
                new Person { FirstName = "<", LastName = ">" },
            });
            Assert.IsTrue(people.HasLoadedOrAssignedValues);
            Assert.IsTrue(people.IsDeferred);
            AssertEqual(events);

            events.Clear();
            people.Clear();
            AssertEqual(events, 
                new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1),
                new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1),
                new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1),
                new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1),
                new ListChangedEventArgs(ListChangedType.Reset, 0, -1));
            Assert.IsFalse(people.IsDeferred);

            // Add()/AddRange() after a Clear has events.
            events.Clear();
            people.Add(new Person { FirstName = "A", LastName = "B" });
            people.AddRange(new[]{
                new Person { FirstName = "1", LastName = "2" },
                new Person { FirstName = "<", LastName = ">" },
            });
            AssertEqual(events, 
                new ListChangedEventArgs(ListChangedType.ItemAdded, 0, -1),
                new ListChangedEventArgs(ListChangedType.ItemAdded, 1, -1),
                new ListChangedEventArgs(ListChangedType.ItemAdded, 2, -1));

            events.Clear();
            var p = new Person { FirstName = "{", LastName = "}" };
            people.Insert(1, p);
            AssertEqual(events, new ListChangedEventArgs(ListChangedType.ItemAdded, 1, -1));

            events.Clear();
            Assert.IsTrue(people.Remove(p));
            AssertEqual(events, new ListChangedEventArgs(ListChangedType.ItemDeleted, 1, -1));

            events.Clear();
            people.RemoveAt(0);
            AssertEqual(events, new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1));

            events.Clear();
            people[0] = p;
            AssertEqual(events,
                new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1),
                new ListChangedEventArgs(ListChangedType.ItemAdded, 0, -1));
        }
开发者ID:nlhepler,项目名称:mono,代码行数:66,代码来源:EntitySetTest.cs

示例3: ListChanged_NoSource

        public void ListChanged_NoSource()
        {
            // When is ListChanged emitted?
            // It's not always when you think it would be.
            // It depends on whether there's a Source present.
            var people = new EntitySet<Person>();
            var events = new List<ListChangedEventArgs> ();
            people.ListChanged += (o, e) => events.Add(e);

            people.Add(new Person { FirstName = "A", LastName = "B" });
            AssertEqual(events);

            events.Clear();
            people.Clear();
            AssertEqual(events, new ListChangedEventArgs(ListChangedType.Reset, 0, -1));

            events.Clear();
            people.AddRange(new[]{
                new Person { FirstName = "1", LastName = "2" },
                new Person { FirstName = "<", LastName = ">" },
            });
            AssertEqual(events);

            events.Clear();
            var p = new Person { FirstName = "{", LastName = "}" };
            people.Insert(1, p);
            AssertEqual(events, new ListChangedEventArgs(ListChangedType.ItemAdded, 1, -1));

            events.Clear();
            Assert.IsTrue(people.Remove(p));
            AssertEqual(events);

            events.Clear();
            people.RemoveAt(0);
            AssertEqual(events, new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1));

            events.Clear();
            people[0] = p;
            AssertEqual(events,
                new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1),
                new ListChangedEventArgs(ListChangedType.ItemAdded, 0, -1));
        }
开发者ID:nlhepler,项目名称:mono,代码行数:42,代码来源:EntitySetTest.cs

示例4: RemoveReplacemant

 public void RemoveReplacemant(Lesson L)
 {
     replacements.Remove(L);
     EntitySet<Lesson> query = new EntitySet<Lesson>();
     foreach (Group g in L.Groups)
         query.AddRange(
     haveReplacement.
         Where(r => r.Day == L.Day).
         Where(r => r.Number == L.Number).
         Where(r => r.Groups.Contains(g))
         );
     foreach (Lesson l in query)
         haveReplacement.Remove(l);
     RefreshFact();
 }
开发者ID:ZAYEC77,项目名称:Susie,代码行数:15,代码来源:Replacement.cs


注:本文中的EntitySet.AddRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。