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 8411623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:28:03+00:00 2026-06-10T00:28:03+00:00

I am having a lambda expression which can fetch multiple records from my table.

  • 0

I am having a lambda expression which can fetch multiple records from my table.

Here is the expression

public sys_Log_Deposits_Interest_Master GetDepositsPendingRecord(string glCode, int fromDateID)
        {
            using (var db = new DataClasses1DataContext())
            {
               var deposit = db.sys_Log_Deposits_Interest_Masters.Where(deposits => deposits.cGLCode.Equals(glCode) && deposits.nFromDateID.Equals(fromDateID));
               return deposit; 
            }
        }

I am getting an Error Cannot implicitly convert type IQueryable To Table Object.

I want to return the table object to my Update method which will update some fileds of the result.

Here is my Update method

public void UpdatePendingRecords(string glCode, int fromDateID)
        {
            using (var db = new DataClasses1DataContext())
            {

                var deposit = GetDepositsPendingRecord(glCode, fromDateID);

                foreach (var pending in deposit)
                {
                    pending.cAuthorizedStatus = "Authorized";
                    pending.dAuthorizedOn = DateTime.Now;
                    pending.cAuthorizedBy = HttpContext.Current.User.Identity.Name;

                }
}
}

Currently I am not able to get it working.

Can anyone help me with this query?

Any help is much appreciated.

  • 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-10T00:28:05+00:00Added an answer on June 10, 2026 at 12:28 am

    It’s an IQueryable<T> where T is whatever type sys_Log_Deposits_Interest_Masters is a table of. e.g. IQueryable<Log_Deposits_Interest_Master> etc.

    Note that the table class that sys_Log_Deposits_Interest_Masters is an instance of also implements that interface. The result is a different implementation that has information to know that it should take it’s results from there, and also apply the filter in the Where.

    You are also disposing of the context in the wrong place, because it won’t exist by the time the values are enumerated through.

    In this case, since you are going to work directly on the results rather than apply any further changes to the query, I’d foreach through the results and yield them in the method, so it gets turned into an enumeration block and the lifetime gets handled differently. Otherwise I’d either work to make sure the datacontext was alive longer by passing it into that method rather than creating it there, or at a pinch I wouldn’t dispose it (but only at a pinch, while the linq2sql people have said not disposing datacontexts is safe, it goes against good practice – you should really assume that it’s never safe to do that – also, it’s only safe most times; do you want to learn when it is or isn’t? Neither do I. Edit: Today by coincidence brings an example where it wasn’t safe with https://stackoverflow.com/a/12002914/400547).

    Edit with examples:

    Best approach:

    public IQueryable<Log_Deposits_Interest_Master> GetDepositsPendingRecord(DataClasses1DataContext db, string glCode, int fromDateID)
    {
      return db.sys_Log_Deposits_Interest_Masters.Where(deposits => deposits.cGLCode.Equals(glCode) && deposits.nFromDateID.Equals(fromDateID));
    }
    
    public void UpdatePendingRecords(string glCode, int fromDateID)
    {
      using (var db = new DataClasses1DataContext())
      {
    
        var deposit = GetDepositsPendingRecord(db, glCode, fromDateID);
    
        foreach (var pending in deposit)
        {
          pending.cAuthorizedStatus = "Authorized";
          pending.dAuthorizedOn = DateTime.Now;
          pending.cAuthorizedBy = HttpContext.Current.User.Identity.Name;
    
        }
    
        //presumably you want to call db.SubmitChanges() here, no?
      }
    }
    

    If you really had to include datacontext creation within the method called you could do

    public IEnumerable<Log_Deposits_Interest_Master> GetDepositsPendingRecord(string glCode, int fromDateID)
    {
      using(var db = new DataClasses1DataContext())
        foreach(Log_Deposits_Interest_Master item in db.sys_Log_Deposits_Interest_Masters.Where(deposits => deposits.cGLCode.Equals(glCode) && deposits.nFromDateID.Equals(fromDateID))
          yield return item;
    }
    

    However this isn’t very useful if you want save the changes you make back to the database, as to do that you must call SubmitChanges() on the same context that you got them from or else rebind them. It also means that if you were to add another Where() on, or use Count() or anything else that can be passed to the database, it won’t be, as we’ve broken the queryable ability at that point.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a checked list box from which i extracted the checked items
I'm having a List<List<String>> , and which contains { {A , B }, {C
I have a lambda expression that gets results from a Dictionary. var sortedDict =
I am having some trouble with compiling a lambda expression for a property getter
I am trying to use boost lambda to avoid having to write trivial functors.
Having a hard time with labels on a ggplot2 plot. Here's a similar plot
I'd like to have a version of lambda , called lambda-r , from within
I have the following lambda expression: IEnumerable<Order> query = _ordersRepository.GetAllByFilter( o => o.OrderStatus.OrderByDescending(os =>
When I try to run the following code I get a Conversion from string
I'm still having problems to write lambda expressions that should create some object and

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.