.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How to create a generic Lambda Expression

Posted By:      Posted Date: October 26, 2010    Points: 0   Category :ASP.Net

I Use entity framework 4.

Here is my model






Each time I want the text for one of these model, I execute this lambda expression p=> p.LangID == 1

Is it possible to create a generic lambda expression function that all of these model can use.?

View Complete Post

More Related Resource Links

Silverlight: Create Animations with XAML and Expression Blend


In this excerpt from his upcoming book, Laurence Moroney explains the basics of Silverlight animation and the animation tools available in Expression Blend.

Lawrence Moroney

MSDN Magazine August 2008

Silverlight: Create a Custom Expression Encoder Publishing Plug-In


Laurence Moroney demonstrates how to employ the Expression Encoder plug-in APIs by building and debugging a simple FTP upload plug-in.

Laurence Moroney

MSDN Magazine February 2008

Implicit-type lambda expression: is it possible?

Hi all, i was plaing around with LINQ and lambda expressions. I was trying to find duplicated files in my system. After a while a realized that duplicated could mean: - same name - same size and extension - ....   So i wrote this code: DirectoryInfo rootDirectory = ....; var groupFiles = selector => rootDirectory.EnumerateFiles("*", SearchOption.AllDirectories).GroupBy(selector).Select(g => new { g.Key, Info = g, Count = g.Count() }).Where(g => g.Count > 1); var groupsByName = groupFiles(f => f.Name); var groupsBySize = groupFiles(f => new { f.Length, f.Extension}); But i get the following error: Error 1 Cannot assign lambda expression to an implicitly-typed local variable So i tryed to make the type explicit and i realized that is not so easy. So what i'm missing?! IMPORTANT. 'm not tying to have the code working. I can solve the issue by duplicating code (even if i hate to do that) I'm rtying to improve my skills with LINQ and Lambda Expressions. Thanks all!!  

RenderAction with Lambda Expression in MVC 3.0 preview 1


Hi all, i have the following, which works:

@{Html.RenderAction("Detail", "Help", new { pageName = "press" });}

But instead i'd like to use a lambda expression to get away from the string bits. I tried using the following (which is the nearest approximation i could figure based on my limited knowledge of the engine):

@{Html.RenderAction<HelpController>(x => x.Detail("press"));}

But i get the following error:

The non-generic method 'System.Web.Mvc.Html.ChildActionExtensions.RenderAction(System.Web.Mvc.HtmlHelper, string, string, System.Web.Routing.RouteValueDictionary)' cannot be used with type arguments

However, i'm reading in the Apress MVC 2.0 book that it is in fact declared as a method that takes type arguments. Am i missing an assembly reference, or has it not been included in the MVC 3.0 Preview 1 build?

Help tloading a dropdownlist using lambda expression??? o/


Hello everyone

Thank you for your time..

I´m trying to load one field from the table using Lambda

 public void Search()


            ddlcity.DataSource = companiesBLL.Find(e => e.city.Equals(e.ID_COMPANY)).ToList();



ddlcity = dropdown

id_city = main Id (primarykey of that table)

but i want to only load the city field from the table Company.

I´d appreciate if anyone could help me.


 public void Bairro()
            ddlBairro.DataSource = empresasBLL.Find(e => e.BAIRRO.Equals(e.ID_EMPRESA)).ToList();

need help in create a regular expression


input string : text1 {{ style="xxxxx" }} text2 [ text3 ] text4 | text5  ' text6 

requirement : extract plain text and style if there is any

result should be   

match 1 group["text"].value=" asd asd"     

match 2:  group["text"].value="text2"  group["style"].value="{{ style="xxxxx" }}"        

 match 3 : group["text"].value="text3"  

match 4  group["text"].value="text4"     

match 5  group["text"].value="text5"        

match 6  group["text"].value="text6"


i got the expression  that extract  style 


 how about text, text can not include chars like  [ ] | '  and style pattern

need help.

Lambda expression


Hi guys,

Anybody please give me the example How to use Lambda expression in linq.please give a simple example and describe it also.


How to use lambda expression to replace if-else


I have a list of possible nodes as a child of parent node, i need to compare the nodeName and if node name matches, i need to get the value and assign it to member variable.

public class Contacts
private string FirstName;
private string LastName;
  public LoadContacts(XmlNode contactNode)
    string[] names={
    foreach(XmlNode child in contactNode)
     if( child.Name == names[0])
       m_firstName = child.Value;
     if(child.Name == names[1])
       m_lastName = child.Value;

Is there a way of re-factor the same code with Lambda expression.

Thanks in Advance.


DRY with Lambda Expression (errors management)


In my current project, I have made a miracle with Lambda Expression. Have you ever implemented something like this:

    public abstract class GenericRepository<TEntity> : IRepository<TEntity> where TEntity : classIEntity
        private readonly ILog _logger;

        protected GenericRepository()
            : this(IoC.GetInstance<IUnitOfWork>(), IoC.GetInstance<ILog>()

Linq: how to share parameters between lambda expressions ?

When using Linq to objects, you will quickly feel the need to pass some parameters from a method to another but it's not so easy because each Linq method is not calling the following one. In a Linq sequence, each method is using the result computed by the previous one. So, local contexts are not visible from one method to another.
The compiler is using two technical different ways to let parameters go out of a method.

Creating a Generic Entity Framework 4.0 Repository

With .NET 4.0 right around the corner, I thought it would be cool to download Visual Studio 2010 beta 2 and start playing around with the next release of Entity Framework.

The initial release of Entity Framework came with a great deal of criticism. To make matters worse, there was a large uproar when it was rumored that Microsoft would be abandoning LINQ to SQL, in favor of Entity Framework. This was because, at the time, many developers felt Entity Framework was an inferior technology to LINQ to SQL. To set things right, Microsoft proactively moved forward with improving Entity Framework, in time for the 4.0 release of the .NET Framework. This is good news because my initial impressions, so far, have been nothing but positive.

A Generic Dialog ViewModel

I worked on a wpf viewmodel for dialogs, because it seemed strange to me that you needed for instance windows forms dialogs to open or save files in wpf. So I set about creating my own wpf dialogs. After creating the dialog viewmodels there still remained a small issue with the library and also I didn't have much time to write an article about it. I however published the library containing the viewmodels for dialogs with another article on my blog

What is Lambda Expressions In LINQ

A lambda expression is an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types.

All lambda expressions use the lambda operator =>, which is read as "goes to". The left side of the lambda operator specifies the input parameters (if any) and the right side holds the expression or statement block. The lambda expression x => x * x is read "x goes to x times x." This expression can be assigned to a delegate type as follows:

How to create 3 tier application using LINQ

As you know that in 3 tier architecture there are three layers

User interface layer. (Is our Form in Windows application and .aspx page in Web application)
Data Access layer. (Which provides interface between Business logic layer and Database)
Business Logic layer.(Which stores your application logic)

Create ToolTip for GridView Header

The following allows you to add a tooltip to the header links of your GridView, a feature that is lacking.

Create And Run Excel Macro At Runtime in C#

You've been tasked with writing a Windows Form application using the .NET Framework that interacts with Microsoft Excel. If you are new to working with Excel in .NET and are having trouble learning how to format certain cells or cell ranges, then this little tip will come in handy. Rather than scour the internet hoping to find the correct set of constants or method syntax for formatting your spreadsheet, use the built in tools in Excel to write the familiar VBA code for you. Then, you can paste the VBA code generated by Excel into the sample C# code below and run it dynamically at runtime.

Create and Use a Typed DataSet by Using Visual C# .NET

This article shows you how to create and use a typed DataSet in a small Web application. Typed DataSets, which inherit from the DataSet class, create first-class members of a DataSet's DataTables and DataColumns, yielding the many benefits that come with the use of strong typing.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend