在使用实体框架时,我们可以使用ToString()或Convert.ToString()内联查询吗?它是否支持所有数据库。(mySQL,oracle,..)或者它与任何人失败
void initialize_matrices(int* a, int* b, int* c);
void fill_matrix(int* matrix);
void add_matrices(int* a, int* b, int* c);
void print_sum_matrix(int* c);
int main()
{
int a[3][3];
int b[3][3];
int c[3][3];
//Q2: define pointers (5)
//Define pointers ap, bp, and cp to the matrices that are defined above
int (*ap)[3][3] = &a; //giving the pointers a location to point to.
int (*bp)[3][3] = &b;
int (*cp)[3][3] = &c;
initialize_matrices(ap, bp, cp);
printf("Matrix a:\n");
fill_matrix(ap);
printf("Matrix b:\n");
fill_matrix(bp);
add_matrices(ap, bp, cp);
print_sum_matrix(cp);
return 0;
}
//Q3: initialize (10)
//loop through the matrices and set each integer value to 0 using pointers
void initialize_matrices(int* a, int* b, int* c)
{
for (int i = 0; i < 3; i++) //rows
{
for (int j = 0; j < 3; j++) //columns
{
*a[i][j] = 0; //accessing & changing the address that the pointer is pointing to?
*b[i][j] = 0;
*c[i][j] = 0;
}
}
}
答案 0 :(得分:1)
ToString()或Convert.ToString()用于C#代码文件,适用于C#构造。它与后端数据库没有任何关系。所以,是的,它将得到所有DB的支持。
答案 1 :(得分:0)
因为,您要将查询的数据转换为列表,您可以这样做---
var pop = from po in ctx.PurchaseOrders
select new SearchItem
{
id = po.PurchaseOrderID,
label = po.SupplierID,
category = po.purchaseorder
}.AsEnumerable() // Now, following Select will operate in memory
.Select(n => new {
n.PurchaseOrderID,
SupplierID = t.SupplierID ?? t.SupplierID.ToString(),
n.puchaseorder
}).ToList();
整个想法是,一旦将查询到的数据从数据库中提取到内存中,就可以使用.ToString()方法,就像我在查询中所述。
答案 2 :(得分:0)
他们之间有一个简单而重要的区别......
ToString()在对象为空时引发异常
因此,对于object.ToString(),如果object为null,则会引发NullReferenceException。
Convert.ToString()在null对象的情况下返回string.Empty
(string)cast在null
的情况下分配对象所以这取决于你的要求,我认为你可以使用
var pop = (from po in ctx.PurchaseOrders
select new SearchItem
{
id = po.PurchaseOrderID,
label = (string)po.SupplierID,
category = "purchaseorder"
}).ToList();