DapperLib / DapperAOT

Build time tools in the flavor of Dapper
Other
357 stars 19 forks source link

Using explicit constructor for DynamicParameters type causes DAP214 error #48

Closed oriches closed 12 months ago

oriches commented 12 months ago

Using something similar to the following causes a couple of DAP214 variable not declared errors, when infact the code works as expected (results returned):

var parameters = new DynamicParameters();
parameters.Add("@StartDate", "2023-06-01");
parameters.Add("@EndDate", "2023-06-30");

When I switch to an anonymous type for the parameters everything is fine - no errors.

var parameters = new 
{
   parameters.Add("@StartDate", "2023-06-01").
   parameters.Add("@EndDate", "2023-06-30")
}
mgravell commented 12 months ago

OK; I'm going to suppress the parameter sniffing for DynamicParameters, and add a suggestion to use an anonymous type instead (they're much more efficient) - unless we detect output etc args

mgravell commented 12 months ago

I assume you mean:

var parameters = new 
{
   StartDate = "2023-06-01",
   EndDate = "2023-06-30",
};

?

oriches commented 12 months ago

I did- thanks

mgravell commented 12 months ago

https://github.com/DapperLib/DapperAOT/commit/df6d435adafaa8392a5c28128e73bb66efccaccd and https://github.com/DapperLib/DapperAOT/issues/51

mgravell commented 12 months ago

fixed in 0.5.0-beta.104