This is a migrated thread and some comments may be shown as answers.

Problem with OrderBy() and First() predicates

3 Answers 109 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dart
Top achievements
Rank 1
Dart asked on 15 Jul 2011, 10:08 PM
Hi Telerik team! I have a problem with your  free ORM.  I try to use fluent api to create database from my model.
 I have to classes:
public class Person
{
    public int Id { get; set; }
    public string Name { get; set; }
    public IList<Action> Actions { get; set; }
}
public class Action
{
    public int Id { get; set; }
    public string ActionName { get; set; }
    public DateTime ActionDate { get; set; }
    public Person Person { get; set; }
    public int PersonId { get; set; }
}
 And i have Fluent Metadata Source:

public class MyFluentMetadataSource : FluentMetadataSource
  {
      protected override IList<MappingConfiguration> PrepareMapping()
      {
          IList<MappingConfiguration> preparedConfigurations = new List<MappingConfiguration>();
          var personConfiguration = new MappingConfiguration<Person>();
          personConfiguration.MapType(p=>new
                                          {
                                              Id = p.Id,
                                              name = p.Name
 
                                          }).ToTable("Persons");
          personConfiguration.HasProperty(p => p.Id).IsIdentity();
          var actionConfiguration = new MappingConfiguration<Action>();
          actionConfiguration.MapType(p => new
          {
              p.Id,
              name = p.ActionDate,
              p.ActionDate, p.PersonId,
 
          }).ToTable("Actions");
          actionConfiguration.HasProperty(p => p.Id).IsIdentity();
          actionConfiguration.HasAssociation(p => p.Person).WithOpposite(c => c.Actions).HasConstraint((p, c) => p.PersonId == c.Id);
          preparedConfigurations.Add(personConfiguration);
          preparedConfigurations.Add(actionConfiguration);
          return preparedConfigurations;
      }
  }

But when i try to execute LINQ query:
var query = from p in dbContext.Persons
                      select new { Id = p.Id,  Name = p.Name,
                      Action = p.Actions.OrderBy(a=>a.ActionDate).First() };
 I get error:
 "Execution of 'System.Linq.Enumerable:First(IEnumerable`1)' on the database server side currently not implemented."


Thank you.


3 Answers, 1 is accepted

Sort by
0
Damyan Bogoev
Telerik team
answered on 18 Jul 2011, 01:37 PM
Hi Dart,

I am afraid that Telerik OpenAccess ORM currently does not support executing queries which use sub selects with the First/FirstOrDefault method.
You could retrieve the data from the database and later on use Linq to Objects to accomplish this goal:

var query = from p in context.Persons.ToList()
select new
{
      Id = p.Id,
      Name = p.Name,
      Action = p.Actions.OrderBy(a => a.ActionDate).FirstOrDefault()
};

I am sorry for the inconvenience caused.

Kind regards,
Damyan Bogoev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Andrew
Top achievements
Rank 1
Veteran
Iron
answered on 02 May 2014, 03:11 PM
do you think we will see First ever be supported?
0
Thomas
Telerik team
answered on 05 May 2014, 07:13 AM
Hello Dart,

so far, not too many users requested this feature. As it is relatively complex to implement, I would not suspect that we are going to get it in the near future. Please feel free to add your request to
http://feedback.telerik.com/Project/114/Feedback/List/All%20Feedback 
so that other users can express their votes too.

Regards,
Thomas
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
Tags
LINQ (LINQ specific questions)
Asked by
Dart
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
Andrew
Top achievements
Rank 1
Veteran
Iron
Thomas
Telerik team
Share this question
or