Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HI, I'm the new for entity framework and I want to learn and use the entity framework.

my Question is:

I want my user be able input connection string so how to write entity framework connection string dynamic? how to Query with entity framework dynamic connection string? If I have procedure, how to use procedure with entity framework dynamic connection string?

thank you that you waste your time for reading my Question.
Posted

1 solution

1.To setup dynamic connection string for Entity Framework (shortly EF), supposing that your ObjectContext class is named MyDataContext, you have to use its constructor that accept a connection string as parameter like in the example below;

2.To query EF by using this dynamic connection string you have to use the code like in the next example:
C#
Student student = null;
using (MyDataContext dataContext = new MyDataContext(yourConnectionString))
                    {
                        var query = from st in dataContext .Students
                            where st.StudentName == "Bill"
                            select st;
                        // 
                        student = query.FirstOrDefault();  
                    }

3.For more details about EF including the using of string procedure in EF see details in the next site: http://www.entityframeworktutorial.net/stored-procedure-in-entity-framework.aspx[^]
 
Share this answer
 
Comments
kornkimhour 9-Jul-14 3:05am    
thank you I will try to do my best
Raul Iloc 9-Jul-14 3:25am    
Welcome, and if my solution helped you, you could accept it!

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