简体   繁体   中英

Entity SQL Anonymous type?

I have a database with 2 tables :

  1. Personal : ID (PK), Name, Code (FK), Birthdate
  2. Social : Code (PK), Address

When I add a ADO.NET Entity Data Model name Model to my project. The Model.Context.tt has only Personals and Socials Dbset<>, so i can only choose 2 tables by using query :

string sql = "SELECT VALUE p FROM SqlEntities.Personals AS p"

SqlEntities is my entity name, so the thing i want is how to make a column in table become the Dbset<>, maybe I don't understand much but how i can use the anonymous type like :

stringsql = "SELECT p.ID, p.Name FROM SqlEntities.Personals AS p"

Model.Context.tt

With projection, it is possible to make the query return only some columns from one table, or to return selected columns from multiple tables joined together. Projection is done with the Select() method and supports anonymous types:

db.Personals.Select(x => new { ID = x.ID, Name = x.Name });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM