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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:02:41+00:00 2026-06-10T00:02:41+00:00

We assume that removing the underlying tables LINQ-to-SQL will cause to throw an exception.

  • 0

We assume that removing the underlying tables LINQ-to-SQL will cause to throw an exception.

We’d assume that removing an expected column would also cause it to break – it won’t be able to insert or update that column. But is that assumption correct? What if we never try to insert or update that column – will it happily SELECT the default value for that column’s datatype?

What changes can we make to the underlying tables that will break LINQ-to-SQL? What changes can we make that it will ignore? Does it validate the database schema at run time, and if so when?

What about removing constraints like primary or foreign keys? Can we add them, remove them, or change them without breaking LINQ-to-SQL?


I know some of the things I can do to the underlying tables, and I know some things I can’t do. The specific case I’m thinking about is whether I can add a nullable column to a table without breaking the dbml. I don’t remember so I wanted to document it here.

  • 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-06-10T00:02:42+00:00Added an answer on June 10, 2026 at 12:02 am

    Exceptions won’t be raised before LINQ-to-SQL generates a select statement and receives a response from the server. And even if the server responds something unexpected (say, a different datatype on a field), it may not cause exceptions until you actively use that field in your code.

    So yes, you can add columns without problems since the generated queries will not refer to it as they’re unknown to your DBML. Linq-To-SQL never sends SELECT * FROM TABLE, rather it will send SELECT [ID], [COL1], [COL2] FROM TABLE nor does it validates the database schema with SQL Server at run-time. So Whether a certain [COL3] exists or not won’t make a difference in the result.


    Just to experiment a little further – it’s certainly not advisable practice -, let’s try deleting and modifying columns that are part of your DBML and see what works or not.

    If you delete [Col2], this will generate an “invalid column name” error since the server will attempt to retrieve all fields for each row, including [col2]:

    var q = from row in table
            select row;
    int id = q.First().id;
    

    However, if you plan to make changes regularly during development, retrieving only the fields that you require will prevent such errors from happening. Because we’re not referring to [Col2], this works:

    var q = from row in table
            select new { row.id, row.Col1 };
    int id = q.First().id;
    

    And a little surprisingly, if you leave Col2 but change it’s datatype to something competely different, say datetime, this is even going to work:

    var q = from row in table
            select new { row.id, row.Col1, row.Col2 };
    int id = q.First().id;
    

    It’s only when actively using the field that it’s not gonna work: (I get “Nullable object must have a value.”)

    var q = from row in table
            select row;
    var col2 = q.First().Col2;
    

    You can even insert rows as long as your new unknown columns are nullable. Say you created a new Col4, this still works!

    table.InsertOnSubmit(new table() { id = 1, col1 = 'A' };
    table.SubmitChanges();
    

    However, be careful if you change the datatype of a column, you won’t be able to insert rows even if you are just passing a null value. If Col1 is a string in your DBML but you changed it to datetime in your database, because Linq-To-SQL generate a proper insert statement for all fields, this doesn’t work : (‘Implicit data type conversion not allowed’)

    table.InsertOnSubmit(new table() { id = 2 };
    table.SubmitChanges();
    

    In summary, as long as the SQL statements LINQ-To-SQL remain valid if you would run them directly on your database, and the data received does not contradict your DBML, it won’t break your code.

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

Sidebar

Related Questions

I am having a few problems quering a DataSet.Tables[0] and removing rows that do
Assume that we have two sets: A=(a_1,a_2,...,a_m) and B=(b_1,b_2,...,a_n) (Not necessarily of same size).
Assume that i have created a client TCP Socket in Activity A. I want
Assume that there's no problem with my header file and some included library. I'm
Assume that I have 2 .php files : index.php and ajax.php This is index.php:
Assume that I receive a Spanish text written in MS word and saved as
Assume that I have a backbone model that has a bunch of boolean attributes:
Assume that we have a large file which can be read in chunks of
Assume that I have login to system using PHP + MySQL, then, after I
Assume that I have a list of employee names from a database (thousands, potentially

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.