如何在linq中添加另一个项目? [英] How to add another item in linq?

查看:193
本文介绍了如何在linq中添加另一个项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用linq to sql.在我的程序的开头,从SQL数据库中加载了一个列表.然后,用户可以添加其他项目.项目不会立即保存,因此无法在数据库表中使用InsertOnSubmit方法.我必须将项目保存在主要的linq变量中,并且当用户按下保存"按钮时,必须将其保存.
我尝试了多种方法来在linq变量中添加项目,但没有一种有效.

谁能帮我吗?

Hi,
I''m using linq to sql. In my program at the beginning, a list is loaded from the SQL database. Then user can add another items. Items are not saved immediately therefore I can not use InsertOnSubmit method in my DB table. I have to save item in the main linq variable and when the user pushes SAVE button it has to be saved.
I tried many ways to add an item in linq variable but none of them worked.

Can anyone help me?

static public void add(UserLoginData item)
{
    try
    {
        item.Order = GetNewOrder();
        UserLoginData[] item_array=new UserLoginData[]{item};
        var usersA = from c in users
                     orderby c.Order
                     select c;
        var usersB = from c in item_array
                     select c;
        var usersC=    usersA.Union(usersB);//related to this error: Local sequence cannot be used in LINQ to SQL implementation of query operators except the Contains() operator.
        MainListUsers = from c in usersA
                orderby c.Order
                select c;
        ListRefresh();
    }
    catch (Exception ex)
    {
        Logging.Log.Report(ex.Message, "Error", new System.Diagnostics.StackFrame(true));
    }

}





Christian Graus写道:
Christian Graus wrote:

这是一个SQL数据库.为什么需要使用LINQ?

It''s a SQL database. Why do you need to use LINQ ?


因此,Linq-to-SQL的用途是什么?


Therefore what is Linq-to-SQL for?

推荐答案

这是一个SQL数据库.为什么需要使用LINQ?
It''s a SQL database. Why do you need to use LINQ ?


这篇关于如何在linq中添加另一个项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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