C# yByCarGroups(int client_id),其中T:DbDataRecord,但没有一个工作列表GetSomeData(),我尝试了您提到的函数签名,它仍然给我以下错误var myList=context.executestreamquery(
C# yByCarGroups(int client_id),其中T:DbDataRecord,但没有一个工作列表GetSomeData(),我尝试了您提到的函数签名,它仍然给我以下错误var myList=context.executestreamquery(,c#,entity-framework,stored-procedures,entity-framework-4,objectdatasource,C#,Entity Framework,Stored Procedures,Entity Framework 4,Objectdatasource,yByCarGroups(int client_id),其中T:DbDataRecord,但没有一个工作列表GetSomeData(),我尝试了您提到的函数签名,它仍然给我以下错误var myList=context.executestreamquery(“exec-spGetProductsByGroup@ProductID={0}”,product_id);告诉我一个错误,结果类型“System.Data.Common.DbDataRecord”可能不是抽象的,并且必须包含默认构造函数,我甚
yByCarGroups(int client_id),其中T:DbDataRecord,但没有一个工作列表GetSomeData(),我尝试了您提到的函数签名,它仍然给我以下错误var myList=context.executestreamquery(“exec-spGetProductsByGroup@ProductID={0}”,product_id);告诉我一个错误,结果类型“System.Data.Common.DbDataRecord”可能不是抽象的,并且必须包含默认构造函数,我甚至尝试使用context.ExecuteStoreQuery>(“exec spGetProductsByGroup@ProductID={0}”,product\u id);同样,它构建得很好,但是页面抛出了一个错误,无法找到对象引用。嗨,你是如何解决问题的<代码>结果类型“System.Data.Common.DbDataRecord”可能不是抽象的,必须包含默认构造函数不能将DbDataRecord与ExecuteStoreQuery一起使用。如果无法定义查询返回的列,则应使用SqlDataReader。如果能够定义返回的列,请创建一个类并使用它来具体化查询。
public List<DbDataRecord> GetData(int product_id)
{
List<DbDataRecord> availableProducts = new List<DbDataRecord>();
var groupData = context.ExecuteStoreQuery<DbDataRecord>("exec
spGetProducts @ProductID={0}", product_id);
availableProducts = groupData.ToList<DbDataRecord>();
return availableProducts;
}
<asp:ObjectDataSource ID="ODSProductAvailability" runat="server"
TypeName="Project.BLL.ProductBL"
SelectMethod="GetData" >
<SelectParameters>
<asp:SessionParameter Name="product_id" SessionField="ProductID" />
</SelectParameters>
</asp:ObjectDataSource>
public List<MyEntity> GetData<MyEntity>(int product_id) where T : class
{
List<MyEntity> myList = new List<MyEntity>();
var groupData = context.ExecuteStoreQuery<MyEntity>("exec
spGetProductsByGroup @ProductID={0}", product_id);
return myList;
}
using (SqlConnection connection = new SqlConnection("your connection string"))
{
SqlCommand command = new SqlCommand(
"exec spGetProductsByGroup @ProductID",
connection);
command.Parameters.Add(product_id);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
List<ProcType> list = new List<ProcType>();
if (reader.HasRows)
{
while (reader.Read())
{
list.Add(new ProcType(){Property1 = reader.GetInt32(0), Property1 = reader.GetString(1));
}
}
reader.Close();
return list;
}
using (AdventureWorksEntities context = new AdventureWorksEntities())
{
string myQuery = @"SELECT p.ProductID, p.Name FROM
AdventureWorksEntities.Products as p";
foreach (DbDataRecord rec in new ObjectQuery<DbDataRecord>(myQuery, context))
{
Console.WriteLine("ID {0}; Name {1}", rec[0], rec[1]);
}
}
string myQuery = @"SELECT p.Name,p.VatNumber FROM MyEntities.Users as p";
ProductList.ItemsSource = new ObjectQuery<DbDataRecord>(myQuery, context);
<DataGrid AutoGenerateColumns="True" x:Name="ProductList"/>
var myList = new ObjectQuery<DbDataRecord>(myQuery, context).ToList();
var myList = context.ExecuteStoreQuery<DbDataRecord>("exec spGetProductsByGroup @ProductID={0}", product_id);
foreach (var rec in context.ExecuteStoreQuery<DbDataRecord>("exec spGetProductsByGroup @ProductID={0}", product_id))
{
for (var ri = 0; ri < rec.FieldCount;ri++)
{
Console.WriteLine(rec.GetDataTypeName(ri)
+" " + rec.GetName(ri)
+" = " + rec.GetValue(ri));
}
}