简体   繁体   中英

ASP.NET/C# - Entity Framework - Classes - Skeleton Method

I currently have a Class which uses the function as such:

var txbl = test.search_bustype("SUP", "Name");

or

foreach(string toWorkWith in test.search_bustype("SUP", "Name")){ // each one }

However, for every Column I want to search using a function, I have to create a separate function.

ie: Columns - bustype, companyID - Would have to have separate functions to search.

My current code is:

public Array search_bustype(string match, string forthat)
    {
        db = new rkdb_07022016Entities2();
        var tbl = (from c in db.tblbus_business select c).ToArray();
        List<string> List = new List<string>();
        int i = 0;
        foreach (var toCheck in tbl)
        {
            if (toCheck.BusType.ToString() == match)
            {
                if (forthat == "Name")
                {
                    List.Add(toCheck.Name);
                }
            }
            i++;
        }
        return List.ToArray();
    }

Is there anyway to possibly, like php actually send the query to the function and then run it there? I haven't been able to find many sources about how to build a secure infrastructure with Entity so I am wondering if anyone knows any way of maybe creating a skeleton method with this framework.

Thanks in advance!

Okay so I stumbled on the Frameworks sources and actually now understand that the Framework itself implements the Skeleton method.

You simply only refer to each query inside the (from c in......

I'll have to look further into how this infrastructure works before I can understand how to further implement functions.

Thank-you for your time however! I will close this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM