GithubHelp home page GithubHelp logo

I get this error when using member methods "variable 'r' of type 'MyModel' referenced from scope '', but it is not defined" about nein-linq HOT 3 CLOSED

jesshannon avatar jesshannon commented on May 18, 2024
I get this error when using member methods "variable 'r' of type 'MyModel' referenced from scope '', but it is not defined"

from nein-linq.

Comments (3)

axelheer avatar axelheer commented on May 18, 2024 1

I see. Member methods on models are not supported. Properties on models are, though.

public class MyModel
{
    public string FirstName { get; set; }
    public string LastName { get; set; }

    [InjectLambda]
    public string FullName => FullNameExpr.Compile().Invoke(this);

    public static Expression<Func<MyModel, string>> FullNameExpr => m => $"{m.FirstName} {m.LastName}";
}

from nein-linq.

axelheer avatar axelheer commented on May 18, 2024

A member method shouldn't be static.

from nein-linq.

jesshannon avatar jesshannon commented on May 18, 2024

Sorry that was a typo while I was trying to work around the issue. The error is still there with a non-static member method.

Here's a more complete demo I've tested in LinqPad, it gives the above error.

using NeinLinq;

void Main()
{
	var result = Users
	.ToEntityInjectable()
	.Select(i => new MyModel {
		FirstName = i.FirstName,
		LastName = i.LastName
	})
	.OrderBy(m => m.GetFullname())
	.Take(1)
	.ToList();		
}

public class MyModel
{
	public string FirstName {get;set;}
	public string LastName {get;set;}
	
    [InjectLambda]
	public string GetFullname() {
		return GetFullnameExpr.Compile().Invoke(this);
	}
	
	public static Expression<Func<MyModel, string>> GetFullnameExpr => (m) => $"{m.FirstName} {m.LastName}";
}

from nein-linq.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.