Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6391699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:43:25+00:00 2026-05-25T03:43:25+00:00

public IList<Event> SearchEvents(DateTime fromDate, DateTime toDate, int categoryId, string eventName ) { var query

  • 0
    public IList<Event> SearchEvents(DateTime fromDate, DateTime toDate, int categoryId, string eventName )
    {

        var  query = context.Events.Include("City").Where(e => e.EventCategoryID == (categoryId <= 0 ? e.EventCategoryID : categoryId)
            && (e.StartDate.Value.Month >= fromDate.Month)
            && (e.EndDate.Value.Month <= toDate.Month)
            && ( e.StartDate.Value.Day>= fromDate.Day) 
            && (e.EndDate.Value.Day <= toDate.Day )
            && (e.StartDate.Value.Year >= fromDate.Year)
            && (e.EndDate.Value.Year <= toDate.Year)
            && string.IsNullOrEmpty(eventName)?  eventName.Contains(e.EventName):   eventName.Contains(eventName));

      return query.ToList();
    }

 public JsonResult SearchEvents(string from,string to,int categoryId, string eventName)
 {
        DateTime frmDate= Convert.ToDateTime(from);
        DateTime toDate = Convert.ToDateTime(to);
        var list = _eventRepository.SearchEvents(frmDate,toDate,categoryId,eventName);  
        return Json(list, JsonRequestBehavior.AllowGet);
 }

i getting Error like:

Error :' A circular reference was detected while serializing an object of type 'CGWeb.Models.Repositories.Models.Event'.

how can solve this issue without removing virtual keyword?.please share..!

//

@Marc Gravell This is my Model

 [Table("Table_Events")]
public partial class Event
{
    [Key]
    public int ID { get; set; }

    //public int? LocationId { get; set; }
    //public int? ImageId { get; set; }
    public string EventName { get; set; }

    [NotMapped]
    public string EventAddress { get; set; }

    public string EventUrl { get; set; }
    public string EventDesc { get; set; }
    public Nullable<System.DateTime> StartDate { get; set; }
    public Nullable<System.DateTime> EndDate { get; set; }

    public Nullable<int> EventCategoryID { get; set; }
    public int CityID { get; set; }
    public int Viewed { get; set; }

    [ForeignKey("EventCategoryID")]
    public virtual EventCategory EventCategory { get; set; }
    //[ForeignKey("ImageId")]
    [NotMapped]
    public virtual ImageViewModel Image { get; set; }

    //[ForeignKey("LocationId")]
    //public virtual Location Location { get; set; }


    [ForeignKey("CityID")]
    public virtual City City { get; set; }

    [NotMapped]
    public bool ISSponsorship { get; set; }

    [NotMapped]
    public Organizer Organizer { get; set; }

    //[NotMapped]
    [ForeignKey("EventId")]
    public virtual IList<Attending> Attending { get; set; }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:43:26+00:00Added an answer on May 25, 2026 at 3:43 am

    This is nothing to do with the virtual keyword; it relates to the object graph. We can’t see your graph, but the classic scenario here is a parent/child bidirectional relationship, i.e. where the parent has a .Children and the child has a .Parent.

    A tree-serializer (such as xml, json, etc) will usually walk any members that are not explicitly marked to be ignored. Hence you would get an infinite loop as it went around that circle forever. Options:

    • use a non-cyclic DTO at this boundary (that is what I would do)
    • mark the offending back-reference for exclusion (the mechanism for this varies per serializer)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query that looks like this: public IList<Post> FetchLatestOrders(int pageIndex, int recordCount)
public static IList<T> LoadObjectListAll<T>() { ISession session = CheckForExistingSession(); var cfg = new NHibernate.Cfg.Configuration().Configure();
the ToSelectList method I have: public static IList<SelectListItem> ToSelectList<T>(this IEnumerable<T> itemsToMap, Func<T, string> textProperty,
I'm using the following c# code: public IList<T> GetAllByExpression(Expression<Func<T, bool>> expression, int startIndex, int
public IList GetClientsByListofID(IList ids) where T : IClient { IList clients = new List();
Suppose I have public IList<Entity> Children { get; set; } public NotifyChildren(Func<object, bool> action,
Suppose I have public class Product: Entity { public IList<Item> Items { get; set;
I have a two classes: public class Question { public IList<Answer> Answers { get;
How would you test the following code? public IList<T> Find(DetachedCriteria criteria) { return criteria.GetExecutableCriteria(session).List<T>();
Class A { Guid ID{get;} ISet<B> ClassBs {get;} } repository public IList<B> GetAsBs(A a)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.