'LinqTOSQL'에 해당되는 글 1건

  1. 2013/07/26 글뻥 Linq to SQL CRUD 패턴
링고게임즈에서 사용하고 있는 서버의 Linq to SQL CRUD 패턴 몇가지를 공개합니다.
(별거 없어욤 =))


1. Create
SomeTable sm = new SomeTable();
sm.Id = _userid;
db.SomeTable.InsertOnSubmit(sm);
db.SubmitChanges();


2.1. Read #1
SomeTable sm = db.SomeTable.Single(e => e.Id == _userid);


2.2. Read #2
var q = from tmp in db.GetTable<SomeTable >()
         where tmp.Id == _userid
         select tmp;


3.1. Update #1
SomeTable  sm = bd.SomeTable.Single(e => e.Id == _userid);
sm.ScoreLink = int.Parse(_score);
db.SubmitChanges();


3.2. Update #2
var g = db.SomeTable.Where(x => x.isRead == 0).ToList();
g.ForEach(t => t.isRead = 1);
db.SubmitChanges();


4. Delete
SomeTable  sm = bd.SomeTable.Single(e => e.Id == _userid);
db.SomeTable.DeleteOnSubmit(sm);



ASP.NET MVC4
2013/07/26 21:03 2013/07/26 21:03