Code |
Code |
but it dosen't work. I don't know why. Enobody help me?
Code |
Code |
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jon Bellamy20 reputationPosted Jul 3, 2009, 3:48 AM EDT
Niladri BiswasRank #3,172 · 452 reputationPosted Jun 7, 2009, 7:55 PM EDT
Mateusz Mistecki3 reputationPosted Jul 4, 2009, 7:55 AM EDT
Igor Shtanko2 reputationPosted Apr 8, 2010, 9:33 AM EDT
This solution works fine and do not require recreating DataContext.
1. You need to reset internal Table
for this you need change private property cachedList of Table
You can use following utility code:
public static class LinqDataTableExtension
{
public static void ResetTableCache(this ITable table)
{
table.InternalSetNonPublicFieldValue("cachedList", null);
}
public static void ResetTableCache(this IListSource source)
{
source.InternalSetNonPublicFieldValue("cachedList", null);
}
public static void InternalSetNonPublicFieldValue(this object entity, string propertyName, object value)
{
if (entity == null)
throw new ArgumentNullException("entity");
if(string.IsNullOrEmpty(propertyName))
throw new ArgumentNullException("propertyName");
var type = entity.GetType();
var prop = type.GetField(propertyName, BindingFlags.NonPublic | BindingFlags.Instance);
if (prop != null)
prop.SetValue(entity, value);
// add any exception code here if property was not found :)
}
}
using something like:
var dSource = Db.GetTable(...)
dSource.ResetTableCache();
2. You need to reset your BindingSource using something like:
_BindingSource.DataSource = new List