修正多處 LINQ-to-Entities 查詢,避免 Nullable .Contains()、.ToString()、Request[] 直接使用造成翻譯失敗。
API 查詢同步改寫 .Contains()、.OrderBy()、複雜 GroupBy/Math.Round,必要時 materialize 或加 HasValue。 Participation rate / kind breakdown 改在記憶體計算,同時檢查整數陣列 .Contains() 的型別安全性。
This commit is contained in:
@@ -26,63 +26,79 @@ public partial class admin_follower_print_ : System.Web.UI.Page
|
||||
//紀錄匯出條件
|
||||
string _query = "";
|
||||
var qry = _db.followers.AsQueryable();
|
||||
if (!string.IsNullOrEmpty(Request["f_number"]))
|
||||
|
||||
// ❌ 錯誤寫法: qry = qry.Where(o => o.f_number.Contains(Request["f_number"].Trim()));
|
||||
// LINQ to Entities 無法轉換 Request[] 方法,必須先轉換為變數再使用
|
||||
string fNumberParam = Request["f_number"]?.Trim();
|
||||
if (!string.IsNullOrEmpty(fNumberParam))
|
||||
{
|
||||
qry = qry.Where(o => o.f_number.Contains(Request["f_number"].Trim()));
|
||||
_query += "信眾編號:" + Request["f_number"].Trim() + "\n";
|
||||
qry = qry.Where(o => o.f_number.Contains(fNumberParam));
|
||||
_query += "信眾編號:" + fNumberParam + "\n";
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(Request["u_name"]))
|
||||
string uNameParam = Request["u_name"]?.Trim();
|
||||
if (!string.IsNullOrEmpty(uNameParam))
|
||||
{
|
||||
qry = qry.Where(o => o.u_name.Contains(Request["u_name"].Trim()));
|
||||
|
||||
_query += "信眾姓名:" + Request["u_name"].Trim() + "\n";
|
||||
|
||||
qry = qry.Where(o => o.u_name.Contains(uNameParam));
|
||||
_query += "信眾姓名:" + uNameParam + "\n";
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Request["address"]))
|
||||
|
||||
string addressParam = Request["address"]?.Trim();
|
||||
if (!string.IsNullOrEmpty(addressParam))
|
||||
{
|
||||
qry = qry.Where(o => o.address.Contains(Request["address"].Trim()));
|
||||
_query += "地址:" + Request["address"].Trim() + "\n";
|
||||
qry = qry.Where(o => o.address.Contains(addressParam));
|
||||
_query += "地址:" + addressParam + "\n";
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(Request["birthday"]))
|
||||
{
|
||||
qry = qry.Where(o => o.birthday >= Convert.ToDateTime(Request["birthday"].Trim()));
|
||||
_query += "生日(起):" + Convert.ToDateTime(Request["birthday"].Trim()).ToString("yyyy/MM/dd") + "\n";
|
||||
DateTime birthdayParam = Convert.ToDateTime(Request["birthday"].Trim());
|
||||
qry = qry.Where(o => o.birthday >= birthdayParam);
|
||||
_query += "生日(起):" + birthdayParam.ToString("yyyy/MM/dd") + "\n";
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Request["birthday2"]) )
|
||||
|
||||
if (!string.IsNullOrEmpty(Request["birthday2"]))
|
||||
{
|
||||
qry = qry.Where(o => o.birthday < Convert.ToDateTime(Request["birthday2"]).AddDays(1));
|
||||
_query += "生日(訖):" + Convert.ToDateTime(Request["birthday2"].Trim()).ToString("yyyy/MM/dd") + "\n";
|
||||
DateTime birthday2Param = Convert.ToDateTime(Request["birthday2"].Trim());
|
||||
qry = qry.Where(o => o.birthday < birthday2Param.AddDays(1));
|
||||
_query += "生日(訖):" + birthday2Param.ToString("yyyy/MM/dd") + "\n";
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Request["country"]))
|
||||
// ❌ 錯誤寫法: _db.countries.Where(x => x.ID == Request["country"].ToString())
|
||||
// LINQ to Entities 無法轉換 Request[].ToString(),必須先轉換為變數再使用
|
||||
string countryId = Request["country"]?.ToString();
|
||||
if (!string.IsNullOrEmpty(countryId))
|
||||
{
|
||||
qry = qry.Where(o => o.country == Request["country"]);
|
||||
_query += "國家:" + (_db.countries.Where(x => x.ID == Request["country"].ToString()).Select(x => x.name_zh).FirstOrDefault()??"" )+ "\n";
|
||||
qry = qry.Where(o => o.country == countryId);
|
||||
_query += "國家:" + (_db.countries.Where(x => x.ID == countryId).Select(x => x.name_zh).FirstOrDefault() ?? "") + "\n";
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Request["country2"]))
|
||||
|
||||
string country2Id = Request["country2"]?.ToString();
|
||||
if (!string.IsNullOrEmpty(country2Id))
|
||||
{
|
||||
if (Request["country2"] == "1")
|
||||
if (country2Id == "1")
|
||||
{
|
||||
qry = qry.Where(o => o.country == "158");
|
||||
qry = qry.Where(o => o.country == "158");
|
||||
}
|
||||
else if (Request["country2"] == "2")
|
||||
else if (country2Id == "2")
|
||||
{
|
||||
qry = qry.Where(o => o.country != "158");
|
||||
|
||||
qry = qry.Where(o => o.country != "158");
|
||||
}
|
||||
_query += "國家:" + (_db.countries.Where(x => x.ID == Request["country2"].ToString()).Select(x => x.name_zh).FirstOrDefault()??"") + "\n";
|
||||
_query += "國家:" + (_db.countries.Where(x => x.ID == country2Id).Select(x => x.name_zh).FirstOrDefault() ?? "") + "\n";
|
||||
}
|
||||
|
||||
//管理報表
|
||||
if (!string.IsNullOrEmpty(Request["year"]))
|
||||
{
|
||||
//title.Text = "信眾管理報表";
|
||||
qry = qry.Where(o => o.join_date.HasValue && o.join_date.Value.Year == Convert.ToInt32(Request["year"]) );
|
||||
//title.Text = "信眾管理報表";
|
||||
int yearParam = Convert.ToInt32(Request["year"]);
|
||||
qry = qry.Where(o => o.join_date.HasValue && o.join_date.Value.Year == yearParam);
|
||||
_query += "年份:" + Request["year"] + "\n";
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(Request["month"]))
|
||||
{
|
||||
qry = qry.Where(o => o.join_date.HasValue && o.join_date.Value.Month == Convert.ToInt32(Request["month"]));
|
||||
int monthParam = Convert.ToInt32(Request["month"]);
|
||||
qry = qry.Where(o => o.join_date.HasValue && o.join_date.Value.Month == monthParam);
|
||||
_query += "月份:" + Request["month"] + "\n";
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Request["season"]) )
|
||||
|
||||
Reference in New Issue
Block a user