コード例 #1
0
 public void TestMethod1()
 {
     using (ProjectDataContext pdc = new ProjectDataContext())
     {
         var customerTable = pdc.Set <Customer>();
         customerTable.Add(new Customer()
         {
             Name = "dinesh", City = "pune", State = "maharashtra", Email = "*****@*****.**"
         });
         pdc.SaveChanges();
         Assert.IsTrue(customerTable != null);
         Assert.IsTrue(customerTable.Count() == 1);
     }
 }
コード例 #2
0
        /// <summary> обновление сущности и всех свойств многие-ко-многим </summary>
        /// <param name="navigationProperties">список свойств</param>
        public virtual void Update(T entity, int id, string[] navigationProperties = null)
        {
            T   foundEntity = dataContext.Set <T>().Find(id);
            var entry       = dataContext.Entry(foundEntity);

            entry.CurrentValues.SetValues(entity);
            if (navigationProperties != null && navigationProperties.Length > 0)
            {
                foreach (var prop in navigationProperties)
                {
                    var collection = entry.Collection(prop);
                    collection.Load();
                    collection.CurrentValue = typeof(T).GetProperty(prop).GetValue(entity);
                }
            }
            dataContext.SaveChanges();
        }
コード例 #3
0
 protected RepositoryBase(ProjectDataContext context)
 {
     dataContext = context;
     dbSet       = dataContext.Set <T>();
 }