0

What kind of entity framwork syntax can i use to achieve a basic sql statement?

In my old code i just did:

        String query = @"   select Equipment.EquipmentTag, EquipmentExtension.ExtensionDescription, Equipment.Description, Equipment.Area, ObjectTypes.TypeName 
                            from Equipment, EquipmentExtension, ObjectTypes
                            where Equipment.EquipmentId = EquipmentExtension.EquipmentID AND EquipmentExtension.ObjectTypeId = ObjectTypes.Id";

        sql.CommandText = query;
        SQLiteDataReader reader = sql.ExecuteReader();

I have tried the equivalent of "select * from equipment":

  var db = new norsokdbEntities();
  var equipmentList = from eq in db.Equipment
  select eq;

But I dont see how i can modify this kind of syntax to join multiple tables. Any thoughts?

snovva
  • 11
  • 1
  • 4
  • http://stackoverflow.com/a/16025457/1707033 -> this is what you must do... – HellBaby Jun 20 '15 at 18:05
  • Similar question http://stackoverflow.com/questions/21051612/entity-framwork-join-3-tables – Amitd Jun 20 '15 at 18:09
  • var equipmentList = from eq in db.Equipment join ee in db.EquipmentExtension on eq.EquipmentId equals ee.EquipmentID select eq ; It only returns fields from the first table. I want to select a couple of fields from each table. – snovva Jun 20 '15 at 19:46
  • you must join them properly...do not try to select like you did in sql... or you can apply a simple select on a view... – HellBaby Jun 20 '15 at 19:59
  • I am joining them by primary key "EquipmentId" in Equipment and foreign key "EquipmentId" in EquipmentExtension. I think that is "properly". Now I want to display the result of the join to the user in a DataGridView. The link you provided is only for columns from one table..... As you can see i want to display the Equipment and all extensions. What is wrong with "SELECT * FROM Equipment, EquipmentExtension WHERE Equipment.EquipmentId = EquipmentExtension.EquipmentId? – snovva Jun 20 '15 at 21:22

0 Answers0