Advertisement
Guest User

Untitled

a guest
Jun 20th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. String cstr = "User Id=snameche;Password=xxx;Host=localhost;Database=guce;Initial Schema=public";
  2. using (var connection = new PgSqlConnection(cstr))
  3. {
  4. using (var contex = new guceEntities(connection))
  5. {
  6. contex.user_groups.Add(new user_groups { username = "Hawaii" , grp_id=10});
  7. contex.SaveChanges();
  8. }
  9. using (var contex = new guceEntities(connection))
  10. {
  11. foreach (var destination in contex.user_groups)
  12. {
  13. Console.WriteLine(destination.username);
  14. }
  15. }
  16. }
  17.  
  18. // Specify the provider name, server and database.
  19. string providerName = "Devart.Data.PostgreSql";
  20. string serverName = "localhost";
  21. string databaseName = "guce";
  22. string userID = "snameche";
  23. string password = "xxx";
  24.  
  25. // Initialize the connection string builder for the
  26. // underlying provider.
  27. SqlConnectionStringBuilder sqlBuilder =
  28. new SqlConnectionStringBuilder();
  29.  
  30. // Set the properties for the data source.
  31. sqlBuilder.DataSource = serverName;
  32. sqlBuilder.InitialCatalog = databaseName;
  33. sqlBuilder.IntegratedSecurity = true;
  34. sqlBuilder.UserID = userID;
  35. sqlBuilder.Password = password;
  36.  
  37. // Build the SqlConnection connection string.
  38. string providerString = sqlBuilder.ToString();
  39.  
  40. // Initialize the EntityConnectionStringBuilder.
  41. EntityConnectionStringBuilder entityBuilder =
  42. new EntityConnectionStringBuilder();
  43.  
  44. //Set the provider name.
  45. entityBuilder.Provider = providerName;
  46.  
  47. // Set the provider-specific connection string.
  48. entityBuilder.ProviderConnectionString = providerString;
  49.  
  50. // Set the Metadata location.
  51. entityBuilder.Metadata = @"res://*/AdventureWorksModel.csdl|
  52. res://*/AdventureWorksModel.ssdl|
  53. res://*/AdventureWorksModel.msl";
  54. Console.WriteLine(entityBuilder.ToString());
  55.  
  56. using (EntityConnection conn =
  57. new EntityConnection(entityBuilder.ToString()))
  58. {
  59. conn.Open();
  60. Console.WriteLine("Just testing the connection.");
  61. conn.Close();
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement