Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public IEnumerable<T> FindAll<T>()
- {
- List<T> allData = new List<T>();
- using (connection = new SqlConnection(this.connectionString))
- {
- this.connection.Open();
- string query = $"SELECT * FROM {this.GetTableName(typeof(T))}";
- string countQuery = $"SELECT COUNT(*) FROM {this.GetTableName(typeof(T))}";
- SqlCommand countCommand = new SqlCommand(countQuery, this.connection);
- int count = (int) countCommand.ExecuteScalar();
- SqlCommand command = new SqlCommand(query, this.connection);
- SqlDataReader reader = command.ExecuteReader();
- using (reader)
- {
- for (int i = 0; i < count; i++)
- {
- allData.Add(this.CreateEntity<T>(reader));
- }
- }
- }
- return allData;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement