如何使用Linq-to-SQL写入数据库 [英] How to write to database using Linq-to-SQL

查看:88
本文介绍了如何使用Linq-to-SQL写入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#SilverLight来创建一个我希望将数据插入数据库表的应用程序。我如何在Linq-to-SQL中执行此操作?



我的数据库表:

http:// bildr.no/view/1412875 [ ^ ]



我的代码:

I am using C# SilverLight to create an application where I whould like to insert data into a database table. How do I do this in Linq-to-SQL?

My database table:
http://bildr.no/view/1412875[^]

My code:

/// <summary>
/// GetAllCarts
/// Sends all carts in database to list
/// </summary>
[OperationContract]
List<Lloyds_Cart> GetAllCarts()
{
    PositionDataClassesDataContext context = new PositionDataClassesDataContext();

    var res = from carts in context.Lloyds_Carts select carts;

    return res.ToList();

}
/// <summary>
/// Create a new Cart
/// </summary>
[OperationContract]
void CreateCart()
{
    PositionDataClassesDataContext context = new PositionDataClassesDataContext();
}

推荐答案

试试这样

Try like this
context.Lloyds_Carts.InsertOnSubmit(Lloyds_Cart);

context.SubmitChanges();





其中Lloyds_Cart是您需要在InsertOnSubmit上传递的实体方法



希望这有帮助



Where Lloyds_Cart is the entity that you need to pass on the InsertOnSubmit method

Hope this helps


嗨朋友,



查看LINQ的以下链接...



连接到SQL数据库并使用LINQ to SQL Designer [ ^ ]

LINQ引言第1部分,共3部分 [ ^ ]

了解LINQ(C#) [ ^ ]

LINQ to SQL [ ^ ]

LINQ to SQL:基本概念和特性 [ ^ ]



问候,

GVPrabu
Hi Friend,

Check the following links for LINQ...

Connect to a SQL Database and Use the LINQ to SQL Designer[^]
LINQ Introduction Part 1 Of 3[^]
Understanding LINQ (C#)[^]
LINQ to SQL[^]
LINQ to SQL: Basic Concepts and Features[^]

Regards,
GVPrabu


我想知道实际的映射编码



因为我的错误显示
i want to know the actuall mapping coding

because mine is showing errors


这篇关于如何使用Linq-to-SQL写入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆