Create Dapper Repository Method for Complex Data

asp.net dapper repository

Question

I want to create a generic repository method for the complex data(Data Result of multiple joins in database). Following are the classes which hold the data . The data comes from SQL is the join of three tables(Tables architecture is same as of class)

      public class InterfaceHeaderSetting
        {
            public Guid Id { get; set; }
            public string CodaDocCode { get; set; }
            public string Company { get; set; }
            public string Currency { get; set; }
            public string DocDescription { get; set; }
            public Screen Screen { get; set; }
            public Interface Interface { get; set; }
        }


        public class Screen
        {
            public Guid Id { get; set; }
            public string Name { get; set; }
        }

       public class Interface
        {
          public Guid Id { get; set; }
          public string Name { get; set; }
        }

I have the repository methods like

public IEnumerable<T> GetAllDynamic(string sql)
{
    return Connection.Query<T>(sql, commandType: CommandType.StoredProcedure).ToList();
}


public T Update(T entity, string sql, object dynamicParameters)
{
    return
        Connection.Query<T>(sql, dynamicParameters, commandType: CommandType.StoredProcedure).SingleOrDefault();
}

I want one more repository method by which I can fill the objects like InterfaceHeaderSetting object.

Popular Answer

I don't think you should reinvent the wheel. For this type of function i think Entity Framework is the solution.

In my projects i let entity framework handle more advanced querys that need joins and let dapper do the simple insert, update and select jobs.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why