1
任何方式傳遞表名作爲參數,並用make廣義函數從數據庫獲取記錄我們可以通過傳遞表值來調用實體框架查詢嗎?
string table = "tbl_Category";
int Id = Class.getLastId(table);
Class.aspx
public static int getLastId(string table)
{
int lastID = 0;
using (HatnEntities context = new HatnEntities())
{
// Fetch Id of last record from table
var result = (from c in context.tbl_Category.OrderByDescending(u => u.Id) select new { Id = c.Id }).FirstOrDefault();
^
//any way to use table name from parameter value"+table+"
if (result != null)
{
lastID = Convert.ToInt32(result.Id);
}
obj.Id = lastID + 1;
context.tbl_Category.Add(obj);
context.SaveChanges();
}
return status;
}
請讓我知道是否有可能