1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Problems with Many-to-many tables, Dapper and Odbc

Discussão em 'StackOverflow' iniciado por fdantas, Abril 28, 2015.

  1. fdantas

    fdantas Administrator Moderador

    I'm working with a Progress Database, with ODBC connection and Dapper, but i have some problems with many-to-many tables.

    My tables:

    User --- UserScreen(Many to many table) --- Screen

    My ModelClasses

    public class User : AttribClass
    {
    /// <summary>
    /// Primary Key (ID)
    /// </summary>
    [Key]
    public int Id { get; set; }

    /// <summary>
    /// AdLogin
    /// </summary>
    public String Login { get; set; }

    /// <summary>
    /// Ad Full Name
    /// </summary>
    public String UserName { get; set; }
    }

    public class Screen : AttribClass
    {
    /// <summary>
    /// Primary key (ID)
    /// </summary>
    [Key]
    public int Id { get; set; }

    /// <summary>
    /// ScreenName
    /// </summary>
    public String ScreenName { get; set; }

    /// <summary>
    /// Screen Description
    /// </summary>
    public String Description { get; set; }
    }


    And finnaly, my code:

    public List<Screen> ReturnScreenByUser(int idUser)
    {
    var connection = DapperDbExtension.GetContext();

    var sql = @"SELECT * from User where Id = ?
    SELECT * FROM Screen WHERE ID IN
    (SELECT screen_id FROM User_Screen WHERE user_Id = ?)";

    using (connection)
    {
    var mapped = connection.QueryMultiple(sql)
    .Map<Screen, User, int>(
    screen => screen.Id,
    user => iduser,
    (screen, adusers) => { screen.Users = users; }
    );

    }

    //Just to test
    //return new List<Screen>();
    }


    But with QueryMultiple doesn't work.

    It's possible that i'm doing something wrong?

    I need a model Class for the Many-to-may table?

    Thank's-a-lot :D

    Continue reading...

Compartilhe esta Página