Reputation: 1993
I'm using .NET RIA Services July Preview to communicate between my Silverlight client and my server. On my server I have an ASP.NET project hosting the Silverlight application. In the ASP.NET application I have a Linq-to-Sql DataModel with a table called Hour. I have extended the Hour entity with 3 properties by creating Hour.shared.cs:
public partial class Hour
{
public string CustomerName { get; set; }
public string ProjectName { get; set; }
public string FullProjectName { get { return this.CustomerName + " - " + this.ProjectName; } }
}
In my domainservice I have a get-method called GetHours. Due the design in Linq, I cannot explicit create a new instance of the Hour entity and through the new entity set the values of my new properties:
var query = from hours in this.Context.Hours
select new Hour()
{
HourID = hours.HourID,
ProjectName = "Hello World"
};
If I just select hours it works just fine but I need to set the ProjectName and CustomerName some how.
Any ideas about how to get around this?
Upvotes: 0
Views: 321
Reputation: 8670
Trying my answer again, last time SO froze on me.
Probably the easiest way to do this would be using a function:
public Hour PopulateHour(Hour hour)
{
hour.CompanyName = "xyz";
hour.ProjectName = "123";
return hour;
}
Then you can use this in your linq query:
var query = from hour in this.Context.Hours
select PopulateHour(hour);
One thing that would make this easier would be if you already had the CompanyId and ProjectId as properties in the Hour class.
Upvotes: 2