开发者

New instance in RIA Domain Service

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?


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜