开发者

How to Show Lookups using Silverlight 4.0 and RIA Services

开发者 https://www.devze.com 2023-04-11 08:56 出处:网络
I have a relational database lets say it consist of an Employee\'s Table and Department\'s table and an EmployeesType Table.

I have a relational database lets say it consist of an Employee's Table and Department's table and an EmployeesType Table.

The employee's table has a DepartmentId, EmployeeTypeId foreign Keys

and now I created a silverlight app with an entity data model and generated a domain service class

and now I want to show employees info in a grid .. of course I can't show Department name and EmployeeType Name in the Grid

I have to use the Include Data annotation in my metadata ..

I did this .. but how can I show all the included fields in one query?

I used this

public IQueryable<Employee> GetEmployeesWithDepartments()
{
      return this.ObjectContext.Employees.Include("Department.EmployeesType");
}

but I manag开发者_如何学JAVAed to show departments only.. What About the other foreign keys?

How can I add them to my query?


When you bind to Employee - you access Department id something like:

{Binding Employee.Department.Id} 

And you access EmployeeType like

{Binding Employee.EmployeesType.Id}

Is that what you asking?


Ok guys .. so after two freaking days of trial and error .. i finally found it

here is what you should do ..

in your getEmployees Method or whatever method of retrival you use you can include all your forign keys as follow

public IQueryable<Employee> GetEmployeesWithDepartments() 
{ 
      return this.ObjectContext.Employees.Include("Department").Include("EmployeeType"); 
} 

and so on for every forgin key you have included in your metadata class

then in the front end you can now have access to the Department Property and use the Binding syntax to bind it with your View

as follow:

<TextBlock Text="{Binding Department.DepartmentName"/>

Thanks for trying to help

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号