我想在我的MVC .net项目中的Amazon AWS中使用DynamoDB。而且我也试图做一个Business-DataAccess-Model分层项目。如何将T对象动态地转换为Amazon DynamoDB文档
我有一个GenericDataRepository类,它实现了Add()功能。
我正在向Add()发送一个T对象,并且我想将其动态地转换为Amazon的Document对象。我该怎么做,最佳做法是什么?
public void Add(T entity)
{
if (entity == null)
return;
var doc = new Document();
// Convert entity to Document automatically
doc["Title"] = entity.Title;
doc["Body"] = entity.Body;
doc["Author"] = entity.Author;
// Convert entity to Document automatically
.....
.....
.....
}
转换太多,因此 - 工作缓慢。 –
是的,但纯手动反射可能很复杂,因为对象可能与子对象,集合等有关。 – Sergey