Entity Framework 6 + Generic – Create Item
using System; using System.Collections.Generic; using System.Data.Entity; using System.Data.Entity.Infrastructure; using System.Linq; using System.Linq.Dynamic; using SoccerDAO; public class GenericService { internal DbContext context; public GenericService(string name) { this.context = new Soccer(name); } … … public bool CreateItem<TEntity>(TEntity item) where TEntity : class { DbSet<TEntity> db_set = context.Set<TEntity>(); try { db_set.Add(item); this.context.SaveChanges(); return true; } catch(Exception ex) { return false; } } } |