Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate a record in a SQL Server CE table using LINQ-to-SQL
    primarykey
    data
    text
    <p>I am building a class library for Windows Phone. As the title suggests, all I want to do is to update a record in a SQL Server CE table. All the methods I came across involve fetching the record from database, manually updating the values and then flushing changes back to the database.</p> <p>Issue here is that, I'm building a library. So I don't know beforehand which columns are going to be there. So, manually updating values is out of question. I want something simpler like <code>UpdateOnSync</code> method which could be used as follows:</p> <pre><code>Contacts.UpdateOnSubmit(contctToUpdate); </code></pre> <p>Where <code>Contacts</code> is a table. Is this somehow possible? Apparently, SQLite for Windows Phone, Windows Azure, etc. have update methods and their style is pretty close to LINQ. How do I update I record without manually modifying values?</p> <p><strong>Update 1:</strong> I just ran following code for testing. It didn't work either!</p> <pre><code>//Get updated items from local to put them in cloud var newLocalItems = (from TEntity p in localTable where p.LastModified &gt; currentTimeStamp select p).ToList(); foreach (var localItem in newLocalItems) { if (localItem.RemoteId == 0) { localItem.LastSynchronized = DateTime.Now; connection.SubmitChanges(); } } </code></pre> <p>Even after modifying the value manually, the rows in database are unmodified. Does the update work only when a single item is fetched?</p> <p>Here's how I get connection:</p> <pre><code>public async void ConfigureSQLCE&lt;T&gt;(T mainDataContext) where T : DataContextBase { MainDB = mainDataContext; //MainDB is class level dynamic } </code></pre> <p>And here's GetConnection method:</p> <pre><code>private async Task&lt;DataContextBase&gt; GetConnection() { if (!MainDB.DatabaseExists()) { MainDB.CreateDatabase(); } return MainDB; } </code></pre> <p>Then I obtain <code>connection</code> by <code>var connection = await GetConnection();</code> The table mentioned above doesn't exist in the class <code>DataContextBase</code>. It rather exists in a class derived from it. How do I go about this situation now?</p> <p><strong>Update 2:</strong> Manually setting property like <code>localItem.LastSynchronized = DateTime.Now</code> started to work magically after I implemented <code>INotifyPropertyChanged</code> in the model.</p> <p>Still, original question stands, how do I update item?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload