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

  • Home
  • SEARCH
  • 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 3390812
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:44:04+00:00 2026-05-18T03:44:04+00:00

When I pass call a Generic Method that return A Func and pass in

  • 0

When I pass call a Generic Method that return A Func and pass in parameter of the Where, that’s dosen’t work. (System.InvalidOperationException: Internal .NET Framework Data Provider error 1025.)
The error is when I want to get the Role information.
For the Role, I need to perform a Where Clause Expression EX: (p => p.LangID == 1)

This code dosen’t Work

In the repository

public Func<T, bool> GetLmbLang<T>() where T:class,IBaseGenericTxt
    {
        int lang = -1;
        lang = Convert.ToInt32(HttpContext.Current.Session["Language"]);
        return (p => p.LangID == lang);
    }

In the controller

                var ViewModel = _db.Contacts.Where(a=> a.IsActive == true).Select(a => new ContactListViewModel { 
                    ContactID = a.ContactID,
                    ContactName = a.ContactName,
                    Role = a.ContactType.ContactTypeTexts.Where(repGeneric.GetLmbLang<ContactTypeText>()).Select(af => af.Txt).FirstOrDefault(),
                    CompanyType = a.Supplier.SupplierName,
                    Addr = a.Address ,
                    Email = a.ContactEmail,
                    Phone = a.ContactPhone
                }).ToList();
                for (int i = 0; i < ViewModel.Count(); i++)
                {
                    Response.Write(ViewModel.ElementAt(i).ContactID + "<br />");
                }

This code WORK

 int lang = -1;
            lang = Convert.ToInt32(Session["Language"]);
            var ViewModel = _db.Contacts.Where(a=> a.IsActive == true).Select(a => new ContactListViewModel { 
                ContactID = a.ContactID,
                ContactName = a.ContactName,
                Role = a.ContactType.ContactTypeTexts.Where(p => p.LangID == lang).Select(af => af.Txt).FirstOrDefault(),
                CompanyType = a.Supplier.SupplierName,
                Addr = a.Address ,
                Email = a.ContactEmail,
                Phone = a.ContactPhone
            }).ToList();
            for (int i = 0; i < ViewModel.Count(); i++)
            {
                Response.Write(ViewModel.ElementAt(i).ContactID + "<br />");
            }

My ContactListViewModel

public class ContactListViewModel
    {
        public int ContactID { get; set; }
        public string ContactName { get; set; }
        public string Role { get; set; }
        public string Company { get; set; }
        public string CompanyType { get; set; }
        public Address Addr { get; set; }
        public string Email { get; set; }
        public string Phone { get; set; }
    }

My List View

 ..... Inherits="System.Web.Mvc.ViewPage<List<mvcinfosite.ViewModels.ContactListViewModel>>" %>
 <table class="genTable">


    <% for (int i = 0;i < Model.Count; i++) { %>
        <tr>
            <td>
                <%: Html.ActionLink(item.ContactName, "Edit", new { id=item.ContactID }) %>
            </td>

            <td>
                <%: item.Role  %>
            </td>

            <td>
                <%: item.Company %>
            </td>

            <td>
                <%: item.CompanyType  %>
            </td>

            <td>
                <%: GlobalHelper.GetAddress(item.Addr) %>
            </td>
            <td>
                <%: item.Email %>
            </td>
            <td>
                <%: item.Phone %>
            </td>
        </tr>

    <% } %>

    </table>
  • 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-05-18T03:44:05+00:00Added an answer on May 18, 2026 at 3:44 am

    As naasking points out, you need to use an Expression of a Func instead of a straight Func:

    public Expression<Func<T, bool>> GetLmbLang<T>() where T:class,IBaseGenericTxt
    {
        int lang = -1;
        lang = Convert.ToInt32(HttpContext.Current.Session["Language"]);
        return (p => p.LangID == lang);
    }
    

    Edit

    Ah, yes, well the problem is that your function doesn’t actually know what class it’s working with at compile time: it only knows that it’s a class, and it implements IBaseGenericTxt. So when you say p.LangId, that part of the expression is calling IBaseGenericTxt.LangId, and not ContactTypeText.LangId.

    You’ll need to build your own expression tree in order to get this to work right. Something like this:

    var paramExpr = Expression.Parameter(typeof(T), "p");
    return Expression.Lambda<Func<T, bool>>(
        Expression.Equal(
            Expression.Property(paramExpr, "LangId"),
            Expression.Constant(lang)),
        paramExpr);
    

    Edit 2

    Two things:

    1. Because LINQ to Entities will try to take anything in a query expression and convert it to a SQL statement, you have to be careful not to go calling methods in the middle of your query. You’ll want to call the GetLmbLang method first and store its value in a variable to use in the query.
    2. As you point out in your comment, because the ContactTypeTexts property does not implement IQueryable, this gets particularly tricky. You have three options as far as I can tell:

      1. Create your entire select statement as an expression tree. This is very annoying and error-prone.
      2. Use Joe Albari’s LinqKit to “Compile” and “Expand” your query. LinqKit will traverse the expression tree and build a new tree wherein your query Expression is converted to its equivalent Func.
      3. Go back to your data context rather than using the ContactTypeTexts property.

    Personally, I would probably go with the last option, like this:

    var lambdaLang = repGeneric.GetLmbLang<ContactTypeText>();
    var ViewModel = _db.Contacts
        .Where(a=> a.IsActive == true)
        .Select(a => new ContactListViewModel { 
        ContactID = a.ContactID,
        ContactName = a.ContactName,
        Role = _db.ContactTypeTexts
            .Where(ct => ct.ContactType.Contacts.Any(
                c => c.ContactId == a.ContactId)
            .Where(lambdaLang)
            .Select(af => af.Txt).FirstOrDefault(),
        CompanyType = a.Supplier.SupplierName,
        Addr = a.Address ,
        Email = a.ContactEmail,
        Phone = a.ContactPhone
    }).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to pass a call back function in a Java method?
I have a question involving calling a class's generic method with a type parameter
When using call_user_func_array() I want to pass a parameter by reference. How would I
I am trying to pass a dataString to to an ajax call using JQuery.
I want to call an ASHX file and pass some query string variables from
So here is the deal. I want to call a class and pass a
I would like to pass an argument(s) to a method being defined using define_method,
Below is some code that is used to pass around a reference to a
I am trying to create an extension method that i can forward a IList
I normally call perl scripts from PHP as below and pass in variables this

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.