谁在 silverlight 中创建数据插入操作的自定义方法?

发布于 2025-01-06 06:52:06 字数 748 浏览 2 评论 0原文

我正在使用 silverlight WCF Ria 服务来处理我的应用程序中与数据库相关的操作。

表,

Post(Id int identity,Title varchar(50), Content varchar(50), Date datetime, Comments varchar(50) );

我确实有一个可以轻松使用的

public void InsertPost( Post post )

{
if ((post.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(post, EntityState.Added);
            }
            else
            {
                this.ObjectContext.Posts.AddObject(post);
            }
}

我可以使用它来更新数据库,但为此我需要传递所有条目,即 Id、内容等,

我需要另一种方法,通过它我可以跳过传递 Id价值观。 我想要这个方法而不是 InsertPost 方法,以及如何在我的 submitbutton_click 事件中使用它。

请帮忙

I am using silverlight WCF Ria service to handle database related operations in my application.

I do have a table

Post(Id int identity,Title varchar(50), Content varchar(50), Date datetime, Comments varchar(50) );

I can easily use

public void InsertPost( Post post )

{
if ((post.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(post, EntityState.Added);
            }
            else
            {
                this.ObjectContext.Posts.AddObject(post);
            }
}

I can use this to update database but for that i need to pass all the entries i.e Id, Content etc

I need one other method through which i can skip passing Id values.
I want this method other than InsertPost method and how can i use that in my submitbutton_click event.

Please help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绳情 2025-01-13 06:52:06

如果您想使用 RIA 服务创建自定义数据插入方法,此答案可能会帮助您

但请记住,如果 CommentsContentdatetime...等。在您的数据库中是可为空,那么您可以使用InsertPost而不指定它们:

Post newPost = new Post { Title = "title" };
ctx.InsertPost(newPost);

If you want to create a custom method for data insertion using RIA Services, this answer might help you.

But remember that if Comments, Content, datetime...etc. are nullable in your database, then you could use the InsertPost without specifying them:

Post newPost = new Post { Title = "title" };
ctx.InsertPost(newPost);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文