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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:07:17+00:00 2026-06-17T08:07:17+00:00

All, I have a SQL Database class structure like public class Database : ISqlObject,

  • 0

All, I have a SQL Database class structure like

public class Database : ISqlObject, IComparable<Database>, IEquatable<Database>
{
    public string Name { get; set; }
    public ISqlObject Parent { get; set; }
    public string Filename { get; set; }
    internal List<Schema> Schemas { get; set; }
    internal List<Table> Tables { get; set; }
    internal List<Constraint> Constraints { get; set; }

    public Database(string name, string filename)
    {
        this.Name = name;
        this.Parent = (ISqlObject)this;
        this.Filename = filename;
    }
    ...
}

protected internal class Table : ISqlObject, IComparable<Table>
{
    public string Name { get; set; }
    public ISqlObject Parent { get; set; }
    public List<Column> Columns { get; set; }
    ...
}

protected internal class Column : ISqlObject, IComparable<Column>
{
    public string Name { get; set; }
    public ISqlObject Parent { get; set; }
    public string Type { get; set; }
    public int MaxLength { get; set; }
    public bool IsNullable { get; set; }
    public bool HasConstraints { get; set; }
    public List<Constraint> Constraints { get; set; }
    ...
}

protected internal class Constraint : IComparable<Constraint>
{
    public string Name { get; set; }
    public ISqlObject Parent { get; set; }
    public bool IsPk { get; set; }
    public string LinkedConstraintName { get; set; }
    public string LinkedColumnName { get; set; }
    public string LinkedTableName { get; set; }
    ...
}

Where the elipsis represent the IComparable implementation and constructors etc.

I have the following code to return the corresponding constraint for current column, using LINQ, but I am consistantly getting linkedConstraints = null

foreach (SqlServer.Column column in tableIndexDict[i].Columns)
{
    if (column.HasConstraints)
    {
        var linkedConstraints = 
            from table in database.Tables 
            from c in table.Columns 
            from con in c.Constraints 
                where con.LinkedTableName.Equals(tableIndexDict[i].Name) && 
                        con.LinkedColumnName.Equals(column.Name) 
            select con;
        foreach (SqlServer.Constraint c in linkedConstraints) <= HERE NullReference Exception.
        {

What am I doing wrong here?

Note: Stack trace:

at System.Linq.Enumerable.<SelectManyIterator>d__31`3.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at UserCost.Export.QlikViewExporter.BuildExclusionTable(Database database) in 
f:\UserCost\UserCost\UserCost\Export\SqlDataExportFactory.cs:line 302
  • 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-17T08:07:18+00:00Added an answer on June 17, 2026 at 8:07 am

    linkedConstraints never can be null in this scenario, because it is lambda.

    You can examine is there linked constraints using this:

    linkedConstraints.Any();
    

    EDIT

    You must examine data you are retrieved. I Assume the con.LinkedTableName or con.LinkedColumnName are null.

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

Sidebar

Related Questions

I have a SQL Server 2000 database with a column of type VARCHAR(255). All
I have a few SQL Server databases (all in one server), containing their own
I have a sql file generated by mysqldump --all-databases . There are many databases
I have nine different databases representing companies, all on the same SQL server 2008
I have an SQL query that returns all companies records ignore the ones with
I have an sql statement that currently is just returning all the end parent
I have all my tables, views, triggers in different files (Table1.sql, Table2.sql, View1.sql,...), and
Using t-sql, how can i find if all SQL Logins have strong passwords on
I currently have the following SQL query that lists all the names of all
i have a number of Tables setup in SQl Server i have transferred all

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.