Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have 3 entity framework connections objects ,
ie. 1> entity1 == for database Master
2> entity2 == for project database
3> entity3 == for local database

how to write generic function which give the single column value to Linq Query from database. as per database types(entity).

Please help me for this.

Thanks and regards
vilas jadhav
Posted

1 solution

Hi,
I got the solution as bellow


XML
public List<T> getRecored_ByQry<T>(string queryString, string strentityName)
       {
           List<T> lst = new List<T>();
           string dbconName = strentityName;
           if (std_con.DefaultContainerName.ToString() == strentityName)
           {
               //queryString = "SELECT VALUE c FROM " + dbconName + "." + tblName + " as c";
               ObjectQuery<T> contactQuery = std_con.CreateQuery<T>(queryString);
               lst = contactQuery.ToList();
               std_con.Refresh(System.Data.Objects.RefreshMode.StoreWins, contactQuery);
           }
           return lst;
       }



call it from code
XML
List<tbl_Project> nlst = new List<tbl_Project>();

        selectQry = "SELECT VALUE User " +
                                " FROM Projects_Entities.tbl_Project " +
                                " AS User WHERE User.str_S_Code ='" + txtProjectCode.Text + "'";

            nlst = getRecored_ByQry<tbl_Project>(selectQry, "Projects_Entities");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900