MapsterMapper / Mapster

A fast, fun and stimulating object to object Mapper
MIT License
4.3k stars 328 forks source link

Mapping doesn't work when using "Include()" in Lambda expression on Adapt #540

Open milad-i opened 1 year ago

milad-i commented 1 year ago

When i use Include() in the Lambda expression and try to use Adapt to mapping, the App crashes, and mapping doesn't work.

var product = _context.Products.Include(p => p.Category).FirstOrDefault(p => p.Id == ID).Adapt<ProductViewModel>();

andrerav commented 1 year ago

I'm sorry to hear that. Do you have some more clues for this mystery, like an error message? Or maybe even.. a stack trace? :)

milad-i commented 1 year ago

Sorry for the lack of details. But there isn't any error. stack trace shows nothing when this line runs. Output just displays details before calling Mapster Adapt. and after a while, debugging will be stop without any exceptions or errors.

Actually, I found the reason today. The problem will appear when both the source and destination object has a relationship property.

Product Model :
public virtual Category Category { get; set; }
//--------------------------------------------------

Category Model :
public virtual ICollection<Product> Products { get; set; }

But .ProjectToType works great in this situation.