Dynamically select columns in runtime using entity framework

前端 未结 5 1259
旧巷少年郎
旧巷少年郎 2020-12-11 05:07

I have an existing function like this

public int sFunc(string sCol , int iId)
{
    string sSqlQuery = \"  select  \" + sCol + \" from TableName where ID = \         


        
5条回答
  •  庸人自扰
    2020-12-11 05:22

    You can do this:

            var entity = _dbContext.Find(YourEntity, entityKey);
            // Finds column to select or update
            PropertyInfo propertyInfo = entity.GetType().GetProperty("TheColumnVariable");
    

提交回复
热议问题