Skip to content

SmartSelector is open source library that allows you to get the specific object fields without a "Select" method.

License

Notifications You must be signed in to change notification settings

kurnakovv/SmartSelector

Repository files navigation

SmartSelector

NuGet NuGet download Visitors MIT License Build/Test

Description

SmartSelector is open source library that allows you to get the specific object fields without a "Select" method.

Idea

Code taken from https://stackoverflow.com/questions/54549506/select-only-specific-fields-with-linq-ef-core

How is it work

public class MyTestObject
{
    public string FirstProperty { get; set; }
    public string SecondProperty { get; set; }
    public string ThirdProperty { get; set; }
}

IQueryable<MyTestObject> myTestObjects = new List<MyTestObject>() 
{
    new MyTestObject { FirstProperty = "a1", SecondProperty = "a2", ThirdProperty = "a3", },
    new MyTestObject { FirstProperty = "b1", SecondProperty = "b2", ThirdProperty = "b3", },
    new MyTestObject { FirstProperty = "c1", SecondProperty = "c2", ThirdProperty = "c3", },
}.AsQueryable();
IQueryable<MyTestObject> result = myTestObjects.SelectFields(new List<string>() { "SecondProperty", "ThirdProperty" });

// Output
FirstProperty: null (default), SecondProperty: 'a2', ThirdProperty: 'a3'
FirstProperty: null (default), SecondProperty: 'b2', ThirdProperty: 'b3'
FirstProperty: null (default), SecondProperty: 'c2', ThirdProperty: 'c3'

Give a star ⭐

I hope this library is useful for you, if so please give a star for this repository, thank you :)

About

SmartSelector is open source library that allows you to get the specific object fields without a "Select" method.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages