Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I'm learning about Entity SQL, I have a problem about code is, when I use :
C#
EntitiesName context = new EntitiesName();
string sql = "SELECT VALUE tmp FROM EntitiesName.Tables AS tmp"
ObjectQuery<Tables> exam = ((IObjectAdapter)context).ObjectQuery.CreateQuery<Tables>(sql);
dataGridView.DataSource = exam.ToList();

The data displays on datagridview. So that code is OK, but when I change query sql to :
C#
string sql = "SELECT tmp.STUDENT, tmp.CLASS FROM EntitiesName.Tables AS tmp"

The code doesn't run, the datagridview is empty, they don't show anything. So when i use SELECT VALUE every thing is good, but when I change SELECT VALUE to SELECT tmp.column name the code doesn't run. I have change the 'Tables' into 'dbDataRecord' but it has same problem, so can anyone help me about this. Thank first !
Posted
Updated 26-Oct-15 23:49pm
v2
Comments
John C Rayan 27-Oct-15 7:15am    
Can you show your columns in GridView.? It has to be matching with the columns in your SQL. You should have columns as STUDENT, CLASS in your GV
Maciej Los 27-Oct-15 17:13pm    

1 solution

The query with value is the Entity SQL. It is processed by the Entity Framework’s Object Services directly. It returns ObjectQuery instead of IQueryable.

In order to specify columns, you may have to have a different approach. It is Raw SQL.

So doing something like below may help you.

C#
 var students = context.<entityname>.SqlQuery("Select tmp.STUDENT, tmp.CLASS EntitiesName.Tables AS tmp").FirstOrDefault<entityname>();
</entityname></entityname>


Here EntityName is your 'Tables'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900