0

i have a problem like below :
I have 3 tables MenuFront, News and SubNews. MenuFront table containt a list of link. Then in News will containt content of each kind & has foreign key with MenuFront.
Some times in News they store as link then detail will store in SubNews then when i write a query to query out News but cannot get the SubNews information. This is the Controller

public partial class Loyalty_News { public Loyalty_News() { this.Loyalty_SubNews = new HashSet<Loyalty_SubNews>(); } public int Id { get; set; } public Nullable<int> CategoryId { get; set; } public string Title { get; set; } public string Description { get; set; } public string Content { get; set; } public string ImagePath { get; set; } public Nullable<int> LikeCount { get; set; } public Nullable<byte> IsHot { get; set; } public Nullable<byte> Status { get; set; } public Nullable<System.DateTime> CDate { get; set; } public string LUser { get; set; } public Nullable<System.DateTime> LDate { get; set; } public int MenuFrontID { get; set; } public virtual Loyalty_MenuFront Loyalty_MenuFront { get; set; } public virtual ICollection<Loyalty_SubNews> Loyalty_SubNews { get; set; } } 

Then here's then query

if (SubMenu != "" && SubMenu != null && Menu != null && Menu != "") { var news = from a in db.Loyalty_News join b in db.Loyalty_SubNews on a.Id equals b.NewsId where a.Id == Int32.Parse(Menu) && b.NewsId == Int32.Parse(SubMenu) select a; if (fromdate != null) { news = news.Where(m => m.CDate >= fromdate); } if (todate != null) { DateTime newtodate = todate ?? DateTime.Now; news = news.Where(m => m.LDate <= System.Data.Entity.DbFunctions.AddDays(newtodate, 1)); } return View(news); } else { var news = from a in db.Loyalty_News join b in db.Loyalty_SubNews on a.Id equals b.NewsId select a; if (Menu != null && Menu != "") { news = news.Where(m => m.Id == Int32.Parse(Menu)); } if (fromdate != null) { news = news.Where(m => m.CDate >= fromdate); } if (todate != null) { DateTime newtodate = todate ?? DateTime.Now; news = news.Where(m => m.LDate <= System.Data.Entity.DbFunctions.AddDays(newtodate, 1)); } return View(news); } 

And in View when i type

@item.Loyalty_SubNews. 

it should show the columns of SubNews but now it only show methods (eg: Where, Union,ToList, ....)

Please help me to get the data of SubNews.

1 Answer 1

1

Try this code snippet

@foreach (var item in Loyalty_SubNews) //because it is list you can't get properties directly, you need to return in loop { <p> @item.property </p> // now here the properties of Loyalty_Subnews will appear } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.