我有一个存储过程,它调用大约 100 列的 View 使用用户想要查看的一组列调用存储过程,并仅返回那些选定的列。
Entity Framework 无法处理它,因为我定义的复杂类型需要 100 列。
假设我用“PersonName, PersonCity”调用存储过程 是否有可能将我在复杂类型中定义的其他98个类型设置为null?
最佳答案
您不能为此使用 Entity Framework 。您应该使用 ADO.net 和数据表来调用 SP 并检查返回的数据结构。像这样的事情:
var cmd = new SqlCommand("spName", db); cmd.CommandType=CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ColumnNames", "a,b,c"); var da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt);
foreach (DataColumn dc in dt.Columns) { //now you have all the information about the results columns }
关于c# - 使用复杂类型调用存储过程 Entity Framework 动态结果集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14958635/