RIA 域服务中的新实例
我正在使用 .NET RIA 服务 7 月预览版在我的 Silverlight 客户端和服务器之间进行通信。在我的服务器上,我有一个托管 Silverlight 应用程序的 ASP.NET 项目。在 ASP.NET 应用程序中,我有一个 Linq-to-Sql 数据模型,其中包含一个名为 Hour 的表。我通过创建 Hour.shared.cs 扩展了 Hour 实体的 3 个属性:
public partial class Hour
{
public string CustomerName { get; set; }
public string ProjectName { get; set; }
public string FullProjectName { get { return this.CustomerName + " - " + this.ProjectName; } }
}
在我的域服务中,我有一个名为 GetHours 的获取方法。由于 Linq 中的设计,我无法显式创建 Hour 实体的新实例,并通过新实体设置新属性的值:
var query = from hours in this.Context.Hours
select new Hour()
{
HourID = hours.HourID,
ProjectName = "Hello World"
};
如果我只选择小时,它工作得很好,但我需要如何设置 ProjectName 和 CustomerName 。
关于如何解决这个问题有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
再次尝试我的答案,上次我愣住了。
可能最简单的方法是使用函数:
然后您可以在 linq 查询中使用它:
如果您已经将 CompanyId 和 ProjectId 作为 Hour 类中的属性,则可以使此操作变得更容易。
Trying my answer again, last time SO froze on me.
Probably the easiest way to do this would be using a function:
Then you can use this in your linq query:
One thing that would make this easier would be if you already had the CompanyId and ProjectId as properties in the Hour class.