title: Linq throwing exception when Null is returned to a string - attribute on a class?
body: <p>I have a Linq query which I am selecting into a string, of course a string can contain null!</p>
  <p>So is there a way I can throw an exception within my Linq query, if I detect a null?</p>
  <p>Can I decorate my class with an attribute that won't let it allow null?</p>
  <p>I would like to wrap my Linq query in a try catch, and as soon as a null is detected then it would enter the catch, and I can handle it.</p>
  <h2>Edit</h2>
  <p>Here's my Linq query, it's quite simple currently. I am going to extend it, but this shows the basic shape:</p>
  <pre><code>var localText = from t in items select new Items { item = t.name }
  </code></pre>
  <p>Basically item is set to t.name, t.name is a string so it could be empty / null is this perfectly legal as its a string and strings can hold NULL.</p>
  <p>So if it returns NULL then I need to throw an exception. Actually it would be handy to be able to throw an exception is NULL or empty.</p>
  <p>I seemed to remember some kind of Attributes that can be set on top of properties that says &quot;Don't accept null&quot; etc.?</p>
  <h2>Edit</h2>
  <p>I think I found it: <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.requiredattribute.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.requiredattribute.aspx</a></p>
  <p>This doesn't allow null or strings so I presume it throws an exception, I have used this with MVC but I am not sure if I can use it with a standard class.</p>