Click here to Skip to main content
13,139,254 members (85,415 online)
Rate this:
 
Please Sign up or sign in to vote.
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-Nov-12 23:31pm
Mogya1.8K

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hi,
I got the solution as bellow


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
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");
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 7 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100