a null reference if set is empty; the first (and only) element of set if it contains one element
The ToObject() method returns the only element of set or returns a null reference if the Set<T> is empty.
The method should not be called for sets that may contain more than one element. Calling the method for these kinds of sets results in different behaviours based on the database platform and the calling context. If you need to retrieve the first element of a set, the combination of Set<T>.GetRange and Set<T>.ToObject has to be used, as in the following example.
Set<Employee> employees = dd.Extent<Employee>()["Name.IsLike({0})", "A%"];
Employee firstWithA = employees.GetRange(0, 1).ToObject();
As a result in this example, the variable firstWithA contains either
a null reference or the first employee matching the criteria.
Set<T>.ToObject | OqlReference.Chapter10