Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I work on .net core 6 vs 2022 i see function have telement
but i don't know what this mean
can you show me please ?
and when use it
are there are any thing best from using telement

What I have tried:

public List<TElement> SQLQuery<TElement>(string sql, string? connectionStringName = null, params StoredParameter[] parameters)
      {
          string ConnectionString = connectionStringName == null ? _ApplicationConfiguration.ConnectionString : _ApplicationConfiguration.GetConnectionString(connectionStringName);
          using (SqlConnection sqlConn = new SqlConnection(ConnectionString))
          {
              using (SqlCommand cmd = new SqlCommand(sql, sqlConn))
              {
                  cmd.CommandText = sql;
                  cmd.CommandType = System.Data.CommandType.StoredProcedure;
                  cmd.CommandTimeout = (int)TimeSpan.FromMinutes(5).TotalSeconds;
                  //cmd.Parameters.AddRange(parameters);
                  foreach (var parameter in parameters)
                  {
                      var paramter = cmd.CreateParameter();
                      paramter.ParameterName = parameter.ParameterName;
                      paramter.Value = parameter.ParameterValue;
                      if (!string.IsNullOrEmpty(parameter.TypeName))
                      {
                          paramter.SqlDbType = SqlDbType.Structured;
                          paramter.TypeName = parameter.TypeName;
                      }
                      cmd.Parameters.Add(paramter);
                  }

                  sqlConn.Open();
                  using (var reader = cmd.ExecuteReader())
                  {
                      var result = reader.MapToList<TElement>();
                      sqlConn.Close();
                      return result;
                  }
              }
          }
Posted
Updated 9-Nov-22 9:42am
v2

1 solution

It's not telement, it's TElement: it's a type placeholder that makes the method work with multiple types without you having to code for all of them separately.
Generic classes and methods | Microsoft Learn[^]
Get used to them, they are a very important part of the language!
 
Share this answer
 

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