none
Linq To Sql Data Types RRS feed

  • General discussion

  • Hello Dears,

    I'm almost new to linq to sql and I have an easy question for you:

    My database has a view named "vw_Customers".

    I have initialize the dbml file with all the tables and views and now the db is accessible throug linq to Sql.

    Now what I want to is is having the complete list of customers loaded in a global variable.

    I have declared my table variable in this way.

    public static Table<vw_Customer> CustomerList;

    now what I want to do is to load the CustomerList with all the users of the view.

    I' don't know how to work with the datatipes... I'm having some trouble and I don't know if it is possible to do it in a direct way like this:

    LinqToSqlComixDataContext db = new LinqToSqlComixDataContext();
    
                Table<vw_Customer> q = from a in db.GetTable<vw_Customer>().AsEnumerable()
                                       orderby a.txtSurname, a.txtName, a.txtCity
                                       select a;
        
    
                CustomerList = q;

    Thanks for you help

    Dario


    Tuesday, September 16, 2014 1:26 PM

All replies

  • Hello Dario,

    >>now what I want to do is to load the CustomerList with all the users of the view.

    I am not quite sure what this means, if it is that you want to load all data from the database to your current project through the vw_Customers view.

    >>I'm having some trouble and I don't know if it is possible to do it in a direct way like this:

    I make a similar query and it throws some errors as “Cannot implicitly convert type “” to “””, is that  you get the similar one? If it is, please try with below sample code:

    List<View_Order> result = (from o in db.GetTable<View_Order>()
    
                                                   orderby o.OrderID, o.OrderName
    
                                                   select o).ToList(); 
    

    Usually, we use the List<T> type.

    Best Regards,

    Fred.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, September 17, 2014 2:57 AM
    Moderator
  • Thanks Fred, 

    This is exactly What I've done ;)

    Tuesday, September 23, 2014 6:20 PM