出于某种原因,我只是无法获得正确的语法来添加 OPTION
Database db = DatabaseFactory.CreateDatabase(Config.DbConnectionString);
using (DbCommand cmd = db.GetSqlStringCommand(string.Format(@" SELECT t.customerID,
t.Photo
FROM SomeTable t
WHERE t.PhotoID = (SELECT MAX(PhotoID) FROM SomeTable WHERE customerID = @{0} OPTION (OPTIMIZE FOR UNKNOWN)
GROUP BY CustomerID ) ", "customerID")))
{
try
{
db.AddInParameter(cmd, "@customerID", DbType.String, customerID);