Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Here's a more automatic method.</strong> It looks at the type/length of each column being inserted, on the fly. </p> <p><strong>Use it like this:</strong></p> <pre><code> foreach (object insert in context.GetChangeSet().Inserts) { FindLongStrings(update); } context.SubmitChanges(); </code></pre> <p><strong>And here's the method:</strong> (It's horribly inefficient so I wouldn't leave it in production code, but if you've got a one-time conversion/import (and it sound like you do), it might do the trick.)</p> <pre><code> public static void FindLongStrings(object testObject) { foreach (PropertyInfo propInfo in testObject.GetType().GetProperties()) { foreach (ColumnAttribute attribute in propInfo.GetCustomAttributes(typeof(ColumnAttribute), true)) { if (attribute.DbType.ToLower().Contains("varchar")) { // kinda crude, but it works... string dbType = attribute.DbType.ToLower(); int numberStartIndex = dbType.IndexOf("varchar(") + 8; int numberEndIndex = dbType.IndexOf(")", numberStartIndex); string lengthString = dbType.Substring(numberStartIndex, (numberEndIndex - numberStartIndex)); int maxLength = 0; int.TryParse(lengthString, out maxLength); string currentValue = (string)propInfo.GetValue(testObject, null); // Do your logging and truncation here if (!string.IsNullOrEmpty(currentValue) &amp;&amp; currentValue.Length &gt; maxLength) Console.WriteLine(testObject.GetType().Name + "." + propInfo.Name + " " + currentValue + " Max: " + maxLength); } } } } </code></pre>
    singulars
    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.
    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