// seems that dlinq allows to change property value only once, the same happens when object is created not only loaded from database
// is there any way how to make it work
//for tests i used the standard dlinq sample database
using System;
using System.Data.SqlClient;
using System.Query;
using System.Data.DLinq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace LINQConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SqlConnection conn = new SqlConnection(@"Data Source=MODA;Initial Catalog=C:\PROGRAM FILES\LINQ PREVIEW\DATA\NORTHWND.MDF;User ID=mike;Password=*********");
DataContext db = new DataContext(conn);
Table<Customer> Customers = db.GetTable<Customer>();
SqlCommand comm = new SqlCommand("SELECT City FROM Customers WHERE CustomerID = @CustomerId", conn);
SqlParameter param = new SqlParameter("CustomerId", System.Data.SqlDbType.NVarChar, 15);
comm.Parameters.Add(param);
Customer customer =
(from c in Customers
where c.City == "London"
select c).First();
conn.Open();
param.Value = customer.CustomerID;
Assert.AreEqual(Convert.ToString(comm.ExecuteScalar()), customer.City);
customer.City = "Riga";
db.SubmitChanges();
Assert.AreEqual(Convert.ToString(comm.ExecuteScalar()), customer.City);
customer.City = "London";
db.SubmitChanges();
// ups London are lost
Assert.AreEqual(Convert.ToString(comm.ExecuteScalar()), customer.City);
conn.Close();
}
}
[Table(Name = "Customers")]
public partial class Customer
{
private string customerId;
private string city;
[Column(Storage = "customerId", Id = true, AutoGen = true)]
public string CustomerID
{
get { return this.customerId; }
}
[Column(Storage = "city")]
public string City
{
get { return this.city; }
set { this.city = value; }
}
}
}

How to change property values twice or more times ??
micr0chip
I just checked against our current bits, and the Current-Version property values get copied to the Database-Version the cache holds for concurrency checks.
If you continue to see this problem after our next release, please let us know.
iShail.com
Umamageswari
I don't have a copy of LINQ in front of me at the moment so I can't test this. I suspect the issue is the original value of the property which your object is caching. When you start, the original value for .City is "London". When you issue the first db.SubmitChanges(); DLINQ checks the original value (London) against the new value (Riga), sees that the new value is different and issues the update command. Key item: It forgets to reset the original value to the new value.
When the second SubmitChanges is called, it compares the new value (London) against the original value (London) not the intemediary value (Riga). Since they are the same, it does not feel the need to submit that change to the database.
If this is the issue, you may have found a bug in the current implementation. It would get nastier if you have nested transactions in the mix here. I would be interested in a response from the team on this item.
Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
shellymm
Yes, you would need to call SubmitChanges to push your updates back to the database. You can make multiple changes and wait to push the updates back until you are finished if you want.
You may be runing into the issue of deferred execution. If you wish to cache the results of a query, use the .ToList or .ToArray method as follows:
Customers custList = (from c in Customers
where c.City == "London"
select c).ToList();
Customer customer = custList.First();
This will cache your results and will not fire another fetch on each iteration of the list. See if this helps resolve your issue.
Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
wesogs