using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace sharpknife { public partial class PTCSource { public static PTCSource GetSource(string name) { PTCSource source = null; using (databaseEntities context = new databaseEntities()) { var query = (from s in context.PTCSource where s.Name == name select s); source = query.FirstOrDefault(); } return source; } public PTCSource() { //this.PTCSourceId = Guid.Empty; } public void Save() { using (databaseEntities context = new databaseEntities()) { if (this.PTCSourceId == Guid.Empty) { this.PTCSourceId = Guid.NewGuid(); this.CreatedOn = DateTime.Now; context.PTCSource.AddObject(this); } else { // DO NOT REMOVE: needed for context loading context.PTCSource.Single(s => s.PTCSourceId == this.PTCSourceId); context.ApplyCurrentValues("PTCSource", this); } context.SaveChanges(); } } public void Delete() { using (databaseEntities context = new databaseEntities()) { context.Attach(this); context.DeleteObject(this); context.SaveChanges(); } } } }