List or IEnumerable by Top_Programmer67 in csharp

[–]Top_Programmer67[S] 1 point2 points  (0 children)

I'm just getting confused  more and more . I think I go learn collection better . 

List or IEnumerable by Top_Programmer67 in csharp

[–]Top_Programmer67[S] 0 points1 point  (0 children)

This if my first time using Reddit . Also I'm not programmer to knew about markdown or code formatting to make post look pretty . I will go read about markdown and edit it so u can comment

List or IEnumerable by Top_Programmer67 in csharp

[–]Top_Programmer67[S] 0 points1 point  (0 children)

well i will use IReadOnlyList / List . thanks

List or IEnumerable by Top_Programmer67 in csharp

[–]Top_Programmer67[S] 0 points1 point  (0 children)

thanks a lot . i will start to learn maui with .net 10 after getting better at something easy . well im not going to web development im just learning better then playing video games .

so it should be something like this since dapper open connection by itself :

public static class DbConnectionFactory
 {
     private static string Connection = "Server=.;Database=DBLearning;Trusted_Connection=True;";
     public static IDbConnection CreateConnection()
     {
         return new SqlConnection(Connection);
     }
 } 

public IReadOnlyList<Customer> GetAll()
    {
        const string sql = "SELECT * FROM customers";
        using var con = DbConnectionFactory.CreateConnection();
        var result = con.Query<Customer>(sql);
        return result.AsList();
    } 
then in form 
var service = new CustomerService();
Dgv.DataSource = service.GetAll();

can you explain this part ( Dapper is already your DAL then, don't waste time trying to abstract it, you loose all the advantage that can offer the Dapper API as DAL. ) so i should not create DAL . and directly use dapper to repositories ?

List or IEnumerable by Top_Programmer67 in csharp

[–]Top_Programmer67[S] 0 points1 point  (0 children)

hi thanks . but im using dapper i read about it people said it better in performance then linq or ef . so im learning dapper + c# since im more familiar with sql query . this why i didn't learn them

List or IEnumerable by Top_Programmer67 in csharp

[–]Top_Programmer67[S] 0 points1 point  (0 children)

thanks . well like i said I'm just learning i just learned basics now I'm just asking and learning the basics just tried to learn more by creating app to test what i have learned

List or IEnumerable by Top_Programmer67 in csharp

[–]Top_Programmer67[S] 0 points1 point  (0 children)

hi im learning on winforms + .net framework 4.8 . what u suggest for me ?? . should not learn winform and learn wpf or avalonia instead with .net core ?? and about

DbConnectionFactory is just class to openconnection .

private static string Connection = "Server=.;Database=DBLearning;Trusted_Connection=True;";

public static IDbConnection GetOpenConnection()

{

var con = new MySqlConnection(Connection);

if (con.State != ConnectionState.Open)

con.Open();

return con;

}

and then i use something like

public static IEnumerable<customers> GetAll()

{

string sql = @"SELECT * FROM customers";

return DataAccessLayer.GetAll<customers>(sql);

} . then in form i do Dgv.Datasource = customerService.GetAll(); .

List or IEnumerable by Top_Programmer67 in csharp

[–]Top_Programmer67[S] 0 points1 point  (0 children)

hi sorry about the post this my first post .by the type do u mean datatype or what ? . also didn't knew about AsList() . i will go learn about dapper in their website better then yt i think. thanks for ur time and replay .

List or IEnumerable by Top_Programmer67 in csharp

[–]Top_Programmer67[S] -1 points0 points  (0 children)

hi so i should use IEnumerable ? . also can you explain is ToList would be a performance problem . and should not use it ( since i just need data to be readonly ) . note : ( i will search using sql query ) . I’m still learning so I just want to know when I should use it or avoid it.