Aşağıdaki kod örneği:Linq Query, "System.Object türünde sabit bir değer oluşturulamadı ...", neden atılıyor?
private void loadCustomer(int custIdToQuery)
{
var dbContext = new SampleDB();
try
{
var customerContext = from t in dbContext.tblCustomers // keeps throwing:
where t.CustID.Equals(custIdToQuery) // Unable to create a constant value of type 'System.Object'.
select new // Only primitive types ('such as Int32, String, and Guid')
{ // are supported in this context.
branchId = t.CustomerBranchID, //
branchName = t.BranchName //
}; //
if (customerContext.ToList().Count() < 1) //Already Tried customerContext.Any()
{
lstbCustomers.DataSource = customerContext;
lstbCustomers.DisplayMember = "branchName";
lstbCustomers.ValueMember = "branchId";
}
else
{
lstbCustomers.Items.Add("There are no branches defined for the selected customer.");
lstbCustomers.Refresh();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
dbContext.Dispose();
}
}
Neyi yanlış yaptığımı anlayamıyorum. Xzx44 almaya devam ediyorum "Sabit bir tip 'System.Object' oluşturulamıyor. Bu bağlamda yalnızca ilkel türler ('Int32, String ve Guid' gibi) destekleniyor."
sayesinde :( – Neel
"t.CustID == custIdToQuery" ve "t.CustID.Equals (custIdToQuery)" arasındaki farkı açıklar mısınız. şimdiden teşekkürler – Neel
@Neel '==' ve '.Equals()' arasındaki fark hakkında açıklama için şu soruya göz atın: http://stackoverflow.com/questions/814878/c-sharp-difference-between- ve eşittir – Alex