<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Entity Framework &#8211; Other Things</title>
	<atom:link href="https://blog.adamzolo.com/tag/entity-framework/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.adamzolo.com</link>
	<description>Blog about Things by Adam Zolotarev</description>
	<lastBuildDate>Mon, 09 Sep 2013 20:59:48 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>
	<item>
		<title>How to Find Column Causing &#8220;String or binary data would be truncated&#8221; Exception in Entity Framework 5.0.</title>
		<link>https://blog.adamzolo.com/entity-framework-5-string-or-binary-data-would-be-truncated/</link>
					<comments>https://blog.adamzolo.com/entity-framework-5-string-or-binary-data-would-be-truncated/#comments</comments>
		
		<dc:creator><![CDATA[Adam Zolo]]></dc:creator>
		<pubDate>Mon, 09 Sep 2013 20:59:48 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<guid isPermaLink="false">http://eazolo.com/blog/?p=18</guid>

					<description><![CDATA[I recently encountered an issue with Entity Framework when it would throw &#8220;String or binary data would be truncated. The statement has been terminated.&#8221; Since the query contained close to 80 fields, I needed an easy way to determine the culprit. Since I already had a class which inherits from DbContext, I added suggested try-catch&#8230;<p><a class="more-link" href="https://blog.adamzolo.com/entity-framework-5-string-or-binary-data-would-be-truncated/" title="Continue reading &#8216;How to Find Column Causing &#8220;String or binary data would be truncated&#8221; Exception in Entity Framework 5.0.&#8217;">Continue reading <span class="meta-nav">&#8594;</span></a></p>]]></description>
										<content:encoded><![CDATA[<p>I recently encountered an issue with Entity Framework when it would throw &#8220;String or binary data would be truncated. The statement has been terminated.&#8221; Since the query contained close to 80 fields, I needed an easy way to determine the culprit. Since I already had a class which inherits from DbContext, I added <a title="EF Exception: String or binary data would be truncated" href="http://stackoverflow.com/questions/13380972/ef-exception-string-or-binary-data-would-be-truncated-the-statement-has-been-t" target="_blank">suggested</a> try-catch block in my SaveChanges() override method:</p>
<pre class="brush: csharp; title: ; notranslate">
public partial class MyContext : DbContext
	{
		public override int SaveChanges()
		{
			try
			{
				return base.SaveChanges();
			}
			catch (DbEntityValidationException ex)
			{
				foreach (var error in ex.EntityValidationErrors)
				{
					Console.WriteLine(&quot;====================&quot;);
					Console.WriteLine(
						&quot;Entity {0} in state {1} has validation errors:&quot;,
						error.Entry.Entity.GetType().Name,
						error.Entry.State);
					foreach (var ve in error.ValidationErrors)
					{
						Console.WriteLine(&quot;\tProperty: {0}, Error: {1}&quot;, ve.PropertyName, ve.ErrorMessage);
					}
					Console.WriteLine();
				}
				throw;
			}
		}
	}
</pre>
<p>You have to make sure that you don&#8217;t set ValidateOnSaveEnabled to false. It is set to true by default, but sometimes it is useful to disable it to improve performance.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.adamzolo.com/entity-framework-5-string-or-binary-data-would-be-truncated/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
