Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm have a database with 2 tables
+ Personal : ID (PK), Name, Code (FK), Birthdate
+ Social : Code (PK), Address
I have added a ADO.NET Entity Data Model, in Model.Context.tt - SqlEntities (My Entities) there only 2 dbset is Personals and Socials so I only can choose a table
SQL
string sql = "SELECT VALUE e FROM SqlEntities.Personals AS e

But how i can choose multi column (anonymous type), examlple :
SQL
string sql = "SELECT e.ID, e.Name FROM SqlEntities.Personals AS e

Do i have to add a column as Dbset, object or what i have to do ?
<img src='http://s10.postimg.org/ycsdafzat/image.jpg' border='0' alt="TE" />
Posted

1 solution

Use LINQ instead:
C#
using(var entity = new SqlEntities)
{
    var personals = entity.Personals.ToList();
}

----------------------------------

[Update]

Do something like:
C#
string sql = "SELECT e.ID, e.Name FROM SqlEntities.Personals AS e"
foreach (DbDataRecord rec in
new ObjectQuery<DbDataRecord>(sql, context))
{
    Console.WriteLine("ID {0}; Name {1}", rec[0], rec[1]);
}

Read the MSDN[^] documentation for the same.

-KR
 
Share this answer
 
v2
Comments
LeeMinhSGU 31-Oct-15 1:54am    
The LINQ i have used already, i used the code same as you posted, but now i'm using the Entity SQL, but it won't run.

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