Linq – SubSonic 3.0.0.3 | SimpleRepository – SortBy [SubSonicIgnore]

linqsubsonic

I got a class with [SubSonicIgnore]:

[SubSonicIgnore]
        public string Name
        {
            get
            {
                return (FirstName ?? string.Empty) + ((MiddleName ?? string.Empty).Length > 0 ? " " + MiddleName + " " : " ") + (SurName ?? string.Empty);
            }
        }

whenver I run my test:

[Test]
        public void Can_Sort()
        {
            IUserRepository _repo = new SqlUserRepository();
            var users = _repo.GetUsers().OrderBy("Name");

It always yield an error:

TestQueryableSorter.Can_Sort : FailedSystem.NotSupportedException: The member 'Name' is not supported

I notice that it only breaks on those properties which has [SubSonicIgnore]. Is this a bug or by design?

I used the class from C:\Program Files\Microsoft Visual Studio 9.0\Samples\1033\CSharpSamples\LinqSamples\DynamicQuery.

Best Answer

You are trying to get SubSonic to order by a column that you are also explicitly telling it to ignore. This is by design, since SubSonic has no concept of the Name member (you are telling it to ignore this property using SubSonicIgnore) you cannot order by, select by or use that property in your SubSonic queries. Looking at your code you could probably do the following instead:

[Test]
public void Can_Sort()
{
  IUserRepository _repo = new SqlUserRepository();
  var users = _repo.GetUsers().OrderBy("FirstNAme");