Skip to content

Commit 7c845f8

Browse files
Added delete method that operates on objects with a designated PK
git-svn-id: http://sqlite-net.googlecode.com/svn/trunk@18 fb26c452-ae10-11de-9734-99f05f10ca21
1 parent 538d3c1 commit 7c845f8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/SQLite.cs

+14
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,20 @@ public T Insert<T> (T obj)
135135
Orm.SetAutoIncPK(obj, id);
136136
return obj;
137137
}
138+
139+
public void Delete<T>(T obj)
140+
{
141+
var type = obj.GetType ();
142+
var pk = Orm.GetColumns (type).Where(c => Orm.IsPK(c)).FirstOrDefault();
143+
if (pk == null) {
144+
throw new ArgumentException("obj does not have a primary key");
145+
}
146+
147+
var q = string.Format("delete from '{0}' where '{1}' = ?",
148+
type.Name,
149+
pk.Name);
150+
Execute(q, pk.GetValue(obj, null));
151+
}
138152

139153
public T Get<T> (object pk) where T : new()
140154
{

0 commit comments

Comments
 (0)