Kudiyarasu M
Kudiyarasu M

Reputation: 37

Dapper Extension Class Mapper

Table -1

Create Table GuestMessageDetails(

id bigint primary  key identity(1,1),
companyname  varchar(250),

FirstName   varchar(250),

FamilyName   varchar(250), 

EmialAdress   varchar(250),

Telephone   bigint,

Country   varchar(250),

ArticleNumber   varchar(250),


SoftwareVersion   varchar(250),

SerialNumber   varchar(250),

PurchaseDate varchar(250),

OrderNumber   varchar(250))

Table -2

Create Table ProductTable (Id bigint primary key identity(1,1),
ArticleImage    varchar(250),
ArticleNumber    Varchar(250))

model

 public class MessageModel
    {
        public string? companyname { get; set; }

        public string? FirstName { get; set; }

        public string? FamilyName { get; set; }

        public string? EmialAdress { get; set; }

        public long Telephone { get; set; }

        public string? Country { get; set; }

        public string? ArticleNumber {get;set;}

        public string? ArticleImage { get; set; }

        public string? SoftwareVersion { get; set; }

        public string? SerialNumber { get; set; }

         public  string? PurchaseDate { get; set; }

         public string? OrderNumber { get; set; }
    }

Now I Want Dapper Extension common two table Class Mapper in Dapper Extension

how create Make Create Respository or Controller

I have Generic Repository Now I Want Two Table Common Generic Class Mapper

Upvotes: 0

Views: 698

Answers (1)

Amit Joshi
Amit Joshi

Reputation: 16389

You are trying to map two tables with one Model (POCO/Entity) class. This is not supported by Dapper-Extensions.

Dapper-Extensions mapping is something like below:

public sealed class ProductMapper : ClassMapper<Product>
{
    public ProductMapper()
    {
        Schema("dbo");
        Table("Products");
        Map(x => x.Id).Key(KeyType.Guid);
        AutoMap();
    }
}

Observe that:

  • the mapper class is derived from ClassMapper<T> where for T you provide your Model class.
  • the Table("Products"); call allows to input only one table name.

Dapper-Extensions is designed to generate simple queries for you which may reduce your 80-90% of the SQL code and make it reusable. For any complex scenario, you should fall-back to Dapper. Writing the query by hand helps best in those complex cases.

I am not sure whether creating View on SQL Server and mapping to it will help or not; it may not be practical solution as well.

If you want to use ORM for complex scenario as well, consider using full ORM like NHibernate.

Upvotes: 0

Related Questions