Problem with OrderBy() and First() predicates

4 posts, 0 answers
  1. Dart
    Dart avatar
    1 posts
    Member since:
    Aug 2010

    Posted 15 Jul 2011 Link to this post

    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.


  2. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 18 Jul 2011 Link to this post

    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!

  3. DevCraft banner
  4. Andrew
    Andrew avatar
    125 posts
    Member since:
    Sep 2008

    Posted 02 May 2014 Link to this post

    do you think we will see First ever be supported?
  5. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 05 May 2014 Link to this post

    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.
     
Back to Top