Click here to Skip to main content
11,647,659 members (69,916 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF LINQ
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.7K

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
0 jyo.net 500
1 F-ES Sitecore 370
2 OriginalGriff 322
3 DamithSL 315
4 CPallini 240
0 OriginalGriff 1,342
1 jyo.net 994
2 DamithSL 971
3 Sergey Alexandrovich Kryukov 873
4 CPallini 795


Advertise | Privacy | Mobile
Web02 | 2.8.150804.3 | Last Updated 7 Nov 2012
Copyright © CodeProject, 1999-2015
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