kavya bathineni

kavya bathineni

  • NA
  • 39
  • 4.1k

How to Navigate 3 tables in EntityFrame work WPF

Dec 1 2016 3:34 AM
I am New to WPF. I has a Country class generated from database using Entity frame work. When I press pageup or pageDown keys navigate to Country class to display Country id and name next elements first to last elements. When i run the code i got Exception please tell me How to navigate 3 tables
My database class:
 
namespace LWLLC.Persistence
{
using System;
using System.Collections.Generic;
public partial class Country
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Country()
{
this.PurchaseOrderLineItems = new HashSet<PurchaseOrderLineItem>();
this.States = new HashSet<State>();
}
public int CountryID { get; set; }
public string Country_Name { get; set; }
public string Country_Code { get; set; }
public Nullable<System.DateTime> CreatedDate { get; set; }
public Nullable<int> CreatedBy { get; set; }
public Nullable<System.DateTime> LastUpdatedDate { get; set; }
public Nullable<int> LastUpdatedBy { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<PurchaseOrderLineItem> PurchaseOrderLineItems { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<State> States { get; set; }
}
}
navigate Businesslogic class is:
 
public Country NavigateCoutryCodebyID(int countryCodeID, NavigationType nav)
{
//.Include("State").Include("PurchaseOrderLineItem")
Country countryCode = null;
try
{
using (LWLLCDBEntities dbEntities = new LWLLCDBEntities())
{
//current item
switch (nav)
{
case NavigationType.First:
countryCode = dbEntities.Countries.FirstOrDefault();
break;
case NavigationType.Last:
countryCode = dbEntities.Countries.OrderByDescending(t => t.CountryID).FirstOrDefault();
break;
case NavigationType.Current:
countryCode = dbEntities.Countries.Where(i => i.CountryID == countryCodeID).FirstOrDefault();
break;
case NavigationType.Next:
countryCode = dbEntities.Countries.Where(i => i.CountryID > countryCodeID).FirstOrDefault();
if (countryCode == null)
countryCode = dbEntities.Countries.FirstOrDefault();
break;
case NavigationType.Prev:
countryCode = dbEntities.Countries.Where(i => i.CountryID < countryCodeID).FirstOrDefault();
if (countryCode == null)
countryCode = dbEntities.Countries.OrderByDescending(t => t.CountryID).FirstOrDefault();
break;
}
}
}
catch (Exception ex)
{
if (log.IsErrorEnabled)
{
log.Error("BusinessLogic.NavigateCountryCodebyID in Business Logic threw exception: ", ex);
}
}
return countryCode;
}