/// <summary>
 /// 创建
 /// </summary>
 /// <param name="db">实体数据</param>
 /// <param name="entity">将要创建的对象</param>
 public virtual void Create(LYProjectEntities db, T entity)
 {
     if (entity != null)
     {
         db.Set <T>().Add(entity);
     }
 }
 /// <summary>
 /// 编辑一个对象
 /// </summary>
 /// <param name="db">实体数据</param>
 /// <param name="entity">将要编辑的一个对象</param>
 /// <param name="isAttach">是否附加到数据库上下文</param>
 public virtual T Edit(LYProjectEntities db, T entity, bool isAttach = true)
 {
     if (isAttach)
     {
         db.Set <T>().Attach(entity);
     }
     db.SaveChanges();
     return(entity);
 }
示例#3
0
        public static void Initial(LYProjectEntities db)
        {
            Article article = new Article();

            article.Title      = "ddd";
            article.Profile    = "dddd";
            article.Content    = "ddddd";
            article.CreateTime = DateTime.Now;
            db.Set <Article>().Add(article);
            db.SaveChangesAsync();
        }
示例#4
0
 /// <summary>
 /// 获取所有
 /// </summary>
 /// <returns>集合</returns>
 public virtual IQueryable <T> GetAll(LYProjectEntities db)
 {
     return(db.Set <T>().AsQueryable());
 }