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 783409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:32:34+00:00 2026-05-14T20:32:34+00:00

what is a good way to write unit tests with a LINQ to SQL

  • 0

what is a good way to write unit tests with a LINQ to SQL DAL?

Currently I am doing some database testing and need to create helper methods that access the database, but I don’t want those methods in my main repo’s.

So what I have is two copies of the DAL, one in my main project and one in the Test project. Is it easier to manage these things if I create a separate project for the data layer? I’m not sure which way is a better way to approach this.

If I do create a data layer project would I move all my repo’s to that project as well? I’m not sure how to properly setup the layers.

Thanks

  • 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-14T20:32:35+00:00Added an answer on May 14, 2026 at 8:32 pm

    I’m using Linq2Sql for my DAL layer and I have it as a seperate project. In my domain project I have a repository interface which I then implement using a custom Linq2SqlCarRepository in my DAL project, this class wraps up the generated Linq2Sql classes.

    eg.
    In Car.Core project

     public interface ICarRepository
     {
        IQueryable<Car> GetAllCars();
        void Add(Car);
     }
    

    I then have a implementation of the interface which wraps up access to the generated Linq2Sql class.

    Car.Data project

    public class SqlCarRepository : ICarRepository
    {
        private CarDataContext _context;
    
        public SqlCarRepository()
        {
            _context = new CarDataContext();
        }
    
        #region ICarRepository Members
    
        public IQueryable<Car> GetAllCars()
        {
            return _context.Cars;
        }
    

    I then have a test project Car.Data.Test which then uses mocks to mock the ICarRepository and tests away. I think this is slightly different to what you’re describing. But I think you want to try and seperate you’re DAL from your application so it’s a peripheral that could be swapped out if you wanted.

    I haven’t got all the completely sorted but I currently have these projects:

    Car.Core         --- All the interfaces and domain objects, DTO's etc
    Car.Core.Tests   --- The tests of the core business logic.
    Car.Web          --- Asp.net MVC frontend
    Car.Web.Tests    --- Tests for the website
    Car.Data         --- The Linq2Sql stuff lives in here
    Car.Data.Tests   --- The tests for the DAL layer
    

    That’s what I’ve got currently though it might not be the best way of doing things now.

    I’d recommend reading through The Onion Architecture and looking at the MVC StoreFront videos for inspiration; good luck.

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

Sidebar

Related Questions

I'm basically just doing some tests to figure out a good way to write
Should I write unit tests for my associations? I haven't found many good resources
Wondering what the best / good way of doing this would be in jQuery.
I have done some looking and I can't figure out a good way to
Here are some (overly) simplified code example to describe my unit testing method. CompanyDataSet.xml
How do you write first responder unit tests? I'm trying to write a test
I'm debugging a set of WCF services. Initially, I created some unit tests, but
Is there a good way to write F# scripts that execute stand-alone without compiling?
What is a good way to arrange images in the footer as shown in
Question What is a good way of assigning a default value to an optional

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.