I use C #, linq and EF4.
I have two tables in my database presented in my Conceptual Model:
Database Tables:
CmsContents
CmsCategories
CmsRelatedCategories (Pure Juction Table)
Entity Type:
CmsContent
CmsCategory
Entyt Set:
CmsContents
CmsCategories
I have some navigation properties:
for CmsContents --> CmsCategories --> Return Collection of Cms CmsCategory
for CmsCategories --> CmsContents --> Return Collection of Cms CmsContents
The data in the database for the connection table are presented:
CategoryId ContentId
7 1
7 2
9 2
I need an Entity Framwork query to retrieve all the CmsContents that are included in the connection table.
I am currently using this code:
var contents = from cnt in context.CmsContents
where cnt.CmsCategories.Any()
select cnt;
What returns:
CmsContents
1
2
I need the result:
CmsContents
1
2
2
I suspect that Any () will only show me DISTINCT values, but I need all of the specified values.
Any idea how to solve it?
Could you write me a LINQ query so that I can get a clear image.
source
share