Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8385985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:48:20+00:00 2026-06-09T17:48:20+00:00

I have the following (which I’ve used in CodeFirst): public class MyForm { public

  • 0

I have the following (which I’ve used in CodeFirst):

public class MyForm
    {
        public int MyFormId { get; set; }
        //Many Form Properties
        public virtual ICollection<AuditItem> AuditItems { get; set; }
    }

public class AuditItem
    {
        public int AuditItemId { get; set; }
        public int MyFormId { get; set; }
        public IAppUser User { get; set; }
        public string ActionByUserStr { get; set; }
        public string ActionByUserDisplayName { get; set; }
        public DateTime DateOfAction { get; set; }
        public string TypeOfAction { get; set; }
        public int Step { get; set; }

        public virtual MyForm MyForm { get; set; }
    }

The AuditItem tracks many actions carried out on MyForm

I’m presenting an index page showing a table where the AuditItem’s last Step = 1.

I do an orderby DateOfAction (because the Step can get setback to 0, so I wouldn’t want it to equal 1 unless it is also the last AuditItem Record for that MyForm), then Select the last record’s step, then query on that. I want to query as early as I can so that I’m not pulling back unrequired MyForms records.

This is the query I have:

var myFormsAtStep1 =
                context.MyForms.Include("AuditItems").Where(
                    mf => mf.AuditItems.OrderBy(ai => ai.DateOfAction).Last().Step == 1);

It gives this error:

LINQ to Entities does not recognize the method 'MyForms.Models.AuditItem Last[AuditItem](System.Collections.Generic.IEnumerable`1[MyForms.Models.AuditItem])' method, and this method cannot be translated into a store expression.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:48:21+00:00Added an answer on June 9, 2026 at 5:48 pm

    Have a look at the list of Supported and Unsupported LINQ Methods.

    Last() is not supported, but First() is, so you can just go on and reverse your ordering and use First() instead of Last().

    mf => mf.AuditItems.OrderByDescending(ai => ai.DateOfAction).First().Step == 1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code which is returning Foo @GET @Produces (MediaType.APPLICATION_XML) public Foo getXML
I am migrating application from JSF1.2/MyFaces+Facelets TO JSF2.1/MyFaces. I have following template which used
I have the following code which is used to upload large files (~6MB) to
I have following thing which i wanted to convert to int. char *ptr; //
I have following xml which same child element (Filed) and I want to get
Hi I have following which is not generating class file for complextypes using bindigs.xml
I have following class which reads and writes an array of objects from/to a
I have following code which have a css class called formErrorContent var promptContent =
In my class i have the following property: Class A { public virtual string
I have following code which should print array of 3072 integers: for(int q=0; q

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.