从EF 4.0中的数据库中获取一些属性 [英] Get some properties from database in EF 4.0
问题描述
大家好,
我正在使用EF 4.0,我的数据库中有2个表"Employee"和"Company",它们之间的关系为one_to_many.我想要从Company表中获取仅具有2个属性(不是全部)的雇员.
在EF 4.0中是否可以执行此操作.
我使用了Include方法,但获得了公司的所有属性,有人可以帮我吗?
Hi all,
I''m using EF 4.0, i have 2 tables "Employee" and "Company" in my database with a relation one_to_many. What I want is to get Employees with only 2 properties (not all) from Company table.
Is there a way to do this in EF 4.0.
I used Include method but i get all properties of company, Can anyone help me?
推荐答案
我不确定EF 4是什么,但是在.NET中,您可以使用SQL轻松做到这一点:
I''m not sure what EF 4 is, but in .NET, you can easily do this with SQL:
SELECT Employee.Column1, Employee.Column2, Employee.Column3, Company.Column4, Company.Column5 FROM Employee INNER JOIN Company ON Employee.CompanyID=Company.ID
第1列,第2列,第3列,第4列& Column5是要显示的列,Employee的CompanyID和Company的ID是相关的列.希望对您有所帮助!
Column1, Column2, Column3, Column4 & Column5 are columns that you want to show, and CompanyID from Employee, and ID from Company are related columns. I hope it helped!
这篇关于从EF 4.0中的数据库中获取一些属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!