[英]Dapper Extension Class Mapper
Table -1表格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表-2
Create Table ProductTable (Id bigint primary key identity(1,1),
ArticleImage varchar(250),
ArticleNumber Varchar(250))
model 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现在我要Dapper Extension公用两张表Class Mapper in Dapper Extension
how create Make Create Respository or Controller如何创建 Make Create Respository 或 Controller
I have Generic Repository Now I Want Two Table Common Generic Class Mapper我有通用存储库,现在我想要两个表通用通用 Class 映射器
You are trying to map two tables with one Model (POCO/Entity) class. This is not supported by Dapper-Extensions.您正在尝试 map 两个表与一个 Model(POCO/实体)class。Dapper-Extensions 不支持。
Dapper-Extensions mapping is something like below: Dapper-Extensions 映射如下所示:
public sealed class ProductMapper : ClassMapper<Product>
{
public ProductMapper()
{
Schema("dbo");
Table("Products");
Map(x => x.Id).Key(KeyType.Guid);
AutoMap();
}
}
Observe that:观察到:
ClassMapper<T>
where for T
you provide your Model class.ClassMapper<T>
,其中T
提供您的 Model class。Table("Products");
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. Dapper-Extensions 旨在为您生成简单的查询,这可能会减少 80-90% 的 SQL 代码并使其可重用。 For any complex scenario, you should fall-back to Dapper.
对于任何复杂的场景,您都应该回退到 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;我不确定在 SQL 服务器上创建视图并映射到它是否有帮助; 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.如果你也想将 ORM 用于复杂场景,请考虑使用完整的 ORM,如 NHibernate。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.