Click here to Skip to main content
15,898,538 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have two tables in db. My "Categorie" table consists of: Id, CategoryName. My "Contents" table consists of: Id, Link, Category.i want to use both tbles in same view how can i achieve that

What I have tried:

i have ni idea what to do? please help me out ,i nees help
Posted
Updated 31-Aug-19 5:14am

1 solution

Based solely off of how it seems your database is arranged the SQL statement for the view would be
SQL
SELECT CategoryID = cat.ID
,      cat.CategoryName
,      ContentID = con.ID
,      ContentLink = con.Link
FROM   Categorie     cat
INNER JOIN Contents  con ON cat.ID = con.Category

Generally I would recommended using names that are not so ambiguous; such as CategoryID and ContentID.

The MVC Model would then start off as
C#
public class CategoryContent {
  public Category category { get; set; }
  public Contents content { get; set; }
}
 
Share this answer
 
Comments
Afzaal Ahmad Zeeshan 31-Aug-19 16:28pm    
The SQL formatting made me vote this post a 5!
MadMyche 31-Aug-19 19:36pm    
Thank you
Member 14552976 18-Sep-19 1:07am    
thanks

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