Giter Club home page Giter Club logo

Comments (4)

axelheer avatar axelheer commented on May 27, 2024

Yeah, if you remove the protected setter of your property (nein-linq "injects" read-only properties only), that should do it.

from nein-linq.

aescg1220 avatar aescg1220 commented on May 27, 2024

I'm having trouble getting it to work with this code (TestInjection always returns 0):
Using NeinLinq.EntityFrameworkCore v5.0.1.

Class:

public class MyFoo
{
	[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
	public int Id { get; set; }
	public string Name { get; set; }

	[NotMapped]
	[InjectLambda]
	public long TestInjection { get; }

	public static Expression<Func<MyFoo, long>> TestInjectionExpr => myFoo => myFoo.Id + 1;
}

Test:

[Fact]
public void TestFooInjection()
{
	UsingDbContext(db =>
	{
		var foo = new MyFoo()
		{
			Name = "Heythere",
		};

		db.MyFoos.Add(foo);
		db.SaveChanges();

		var fooResult = db.MyFoos.ToInjectable().First();
		fooResult.TestInjection.ShouldBeGreaterThan(0);

	});
}

from nein-linq.

aescg1220 avatar aescg1220 commented on May 27, 2024

Also I tried using ToEntityInjectable() and it's still returning 0 for the TestInjection property.

from nein-linq.

axelheer avatar axelheer commented on May 27, 2024

Note to myself: don't answer any questions before second coffee...

NeinLinq intercepts during projection. Thus, without any LINQ query can't happen a thing. In order to use lampda injection you'll need some kind of projection to view models or the like.

I'll play with your use case next week or so, but I don't think there can be a LINQ based solution for this. Maybe implementing an EF Core based interceptor might help here?

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.