Saturday, 15 May 2010

c# - Entity Framework Virtual ICollection How to Query -



c# - Entity Framework Virtual ICollection How to Query -

first of all, new entity framework etc , trying figure things out. have model this:

public class eventinstance { [column("event_instance_id")] public int eventinstanceid { get; set; } [column("customer_id")] public int customerid { get; set; } [column("event_id")] public int eventid { get; set; } [column("start_date_time")] public system.datetime startdatetime { get; set; } public virtual event event { get; set; } }

i need access property in table called eventtimeeventinstances table not included in model. have 2 questions.

if add:

public virtual icollection<eventtimeeventinstance> eventtimeinstances { get; set; }

will effect other areas of our application?

secondly, how access property icollection in query this:

public iqueryable<eventinstance> getinstances(int scheduleid) { // returning instances 3 months datetime daterange = datetime.now.adddays(-180); homecoming eventdbcontext.eventinstances.where (x => x.customerid == multitenantid && x.startdatetime >= daterange) .orderby(x => x.startdatetime).asqueryable(); }

i need able add together eventtimeinstances.eventtimeid == scheudleid query. how can this?

you can utilize in query:

public iqueryable<eventinstance> getinstances(int scheduleid) { // returning instances 3 months datetime daterange = datetime.now.adddays(-180); homecoming eventdbcontext.eventinstances.where(x => x.customerid == multitenantid && x.startdatetime >= daterange && x.eventtimeinstances.any(a => a.eventtimeid == scheudleid) ).orderby(x => x.startdatetime).asqueryable(); }

c# entity-framework

No comments:

Post a Comment