I am glad that currently the issue is fixed on your side.
Let me just add that the NullReferenceException
you were experiencing was due to the fact that the mytextbox.Text
property was taking its value from a property of an object equal to NULL. The reason for that is that the FirstOrDefault()
extension method returns the default value for the source type, if the collection it is executed on is empty. And since User_PhoneTypes
is a referential type, its default value is NULL.
In other words, if User_PhoneTypes
does not contain objects that match the condition specified in the Where()
method, the phonetype
collection will be empty and the FirstOrDefault()
method will return an object of type User_PhoneTypes
which value will be NULL
. Later when you try to access the PhoneTypeName
property of that object the NullReferenceException
will be thrown.
Since you have already found one of the possible solutions in this situation, let me just suggest to you another one. You can check in the domain model the datatype of PhoneTypeCode
and supply the comparison value according to it in the Where()
method. For example, if PhoneTypeCode
, you can compose the statement like this:
(c) c.PhoneTypeCode = 0)
I hope you find this feasible. If you have other questions or experience difficulties, do not hesitate to get back to us.
OpenAccess ORM Q2 2013 brings you a more powerful code generation and a unique Bulk Operations support with LINQ syntax. Check out the list of new functionality and improvements shipped with this release.