Skip to content

Latest commit

 

History

History
44 lines (35 loc) · 2.1 KB

ReadMe.md

File metadata and controls

44 lines (35 loc) · 2.1 KB

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 :)