views:

51

answers:

1

For examples sake, lets say I have a table containing these columns

  • ID (primary key, auto increment)
  • FirstName (32 characters)
  • LastName (32 characters)
  • Picture (binary JPEG data containing on average 10k of data)

Using SubSonic and/or LINQ how can I update only the FirstName column of a record and not try to get the Picture column or try to update the picture column?

Right now the only way I see of doing it is something like this:

var p=Data.People(x=>x.ID==SomeID);
p.FirstName="Foobar";
p.Save();

What happens over the line from what I can tell though is that it completely loads the object and completely saves the object. I don't want to have to transfer over 10k of data for such a simple operation though. How do I fix this?

+3  A: 

Here's an old example from Rob for a SubSonic 3 preview version.

db.Update<Products>().Set(
    x => x.Discontinued == false, 
    x => x.ReorderLevel == 100)
  .Where(x=>x.Category==5)
  .Execute();

http://blog.wekeroad.com/2008/11/12/subsonic-3-0-preview-2

In your terms:

db.Update<People>().Set(
    p => p.FirstName == "FooBar")
  .Where(p => p.ID == SomeId)
  .Execute();
SchlaWiener
Actually your version doesn't compile, so I guess the first version with `==` for updating should work?
Earlz
It is probably using `==` because Expression Trees do not support assignment.
sixlettervariables
Ok, it doesn't throw an error, but this does not work. The database is not changed or anything
Earlz
ah nevermind, I completely forgot about the ending `.Execute()`
Earlz
@sixlettervariables: Didn't know that, thanks. I updated the answer.
SchlaWiener