Click here to Skip to main content
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.6K

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)



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