I am starting to work with LINQ To SQL, and I am trying to solve this primitive problem. I have a very simple table with two columns.
- Nick is the key, unique
- Password
I would like to delete a line with some nick value.
I am using this method:
public void DeleteSpiritUser(string nick) { var user = from u in _dc.Spirit_Users where u.Nick == nick select u; using (var scope = new TransactionScope()) { _dc.Spirit_Users.DeleteOnSubmit(user.First()); try { _dc.SubmitChanges(); } catch (Exception exception) { throw exception; } scope.Complete(); } }
The problem is that I have to use user.First (), if I need one row, I would like select with LINQ to only know one row is IEnumerable, because Nick is unique.
c # linq-to-sql
user572844
source share