Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3607280
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:21:22+00:00 2026-05-18T21:21:22+00:00

Using VS2008 and Sql CE 3.5, and preferably Linq to Sql. I’m learning database,

  • 0

Using VS2008 and Sql CE 3.5, and preferably Linq to Sql.

I’m learning database, and unsure about DAL methods return types and how/where to map the data over to my business objects: I don’t want direct UI binding.

A business object class UserData, and a class UserDataList (Inherits List(Of UserData)), is represented in the database by the table “Users”. I use SQL Compact and run SqlMetal which creates dbml/designer.vb file. This gives me a class with a TableAttribute:

<Table()>  _
Partial Public Class Users

I’m unsure how to use this class. Should my business object know about this class, such that the DAL can return the type Users, or List(Of Users) ?

So for example the “UserDataService Class” is a part of the DAL, and would have for example the functions GetAll and GetById. Will this be correct : ?

Public Class UserDataService

Public Function GetAll() As List(Of Users)
    Dim ctx As New MyDB(connection)
    Dim q As List(Of Users) = From n In ctx.Users Select n
    Return q
End Function

Public Function GetById(ByVal id As Integer) As Users
    Dim ctx As New MyDB(connection)
    Dim q As Users = (From n In ctx.Users Where n.UserID = id Select n).Single
    Return q
End Function

And then, would I perhaps have a method, say in the UserDataList class, like:

Public Class UserDataList
   Inherits List(Of UserData)

Public Sub LoadFromDatabase()

      Me.clear()
      Dim database as New UserDataService
      dim users as List(Of Users)
      users = database.GetAll()

      For each u in users
          dim newUser as new UserData
          newUser.Id = u.Id
          newUser.Name = u.Name
         Me.Add(newUser)
      Next

End Sub

End Class

Is this a sensible approach? Would appreciate any suggestions/alternatives, as this is my first attempt on a database DAL.

cheers!

EDIT:

Seems I have problems with the query/return types of GetAll() and GetAllById().. Not sure how to do this..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:21:23+00:00Added an answer on May 18, 2026 at 9:21 pm

    Open Visual Studio.

    Open the server connections tab and connect to your SQL server.

    In your project, add a new Linq To SQL Data Context. This will add a new file. Once this is open in the designer, drag and drop the tables from your database into the SQL Data context.

    At this point, you can now go to your code and say.

    NameOfYourDataContext dc = new NameOfYourDataContext();
    
    var query = from row in dc.table
                where property == 0 //Filter if needed
                select row;
    
    //OR var query = dc.table.where(row => row.Property == 0);
    
    int i = 0;
    
    foreach(var row in query)
    {
       row.property = i++;
    }
    
    dc.SubmitChanges();
    

    If you are really trying to control the class that is created then I recommend that you look into the SQL Metal tool which can create data contexts from an xml file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using LINQ to SQL with Sql Server Compact Edition 3.5 and VS2008.
I'm using MS SQL 2000, VS2008, MVC and C#. I'm trying to insert and
I'm using VS2008 to develop an app. Now, whenever I connect to database in
I am generating the LINQ-to-SQL DataContext and entity classes for a database. The database
I'm using VS2008 with MS Sql Server 2005 to create an application. I've used
I'm using VS2008 (.NET 3.5) and Entity Framework over SQL Server. I'm hoping to
I'm writing a report using SQL Server BIDS (Business Intelligence Development Studio, VS2008), and
I'm building up a query using LINQ to SQL and C# and when I
I have an asp.net application developed. It uses LINQ to SQL to access database,
I'm trying to start using LINQ and specifically LINQ to SQL but I'm having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.