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

  • Home
  • SEARCH
  • 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 6592109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:30:45+00:00 2026-05-25T17:30:45+00:00

I’m using linq2sql against an old database system. In this system there are three

  • 0

I’m using linq2sql against an old database system. In this system there are three tables, Invoices, Users, and SignupUsers. The Invoices table has a UID field that usually references the UID key on the Users table. BUT, it also has a IsSignup bit field that indicates the UID field should reference the UID key on the SignupUsers table.

I don’t really care about the relationship with the SignupUsers table, but we do have a problem where it is very easy to forget to check the “IsSignup” value when using the linq2sql entities. I’d like to make the Invoices->Users relationship in the entities conditional upon the IsSignup bit field.

I’ve tried a couple of approaches. First I tried setting up OnLoaded:

public partial class Invoice
{
    partial void OnLoaded()
    {
        if (IsSignup)
        {
            InvoiceUser = null;
        }
    }
}

This fails because it tries to actually set the UID field to null when it saves the invoice back– which we cannot do.

I poked around with DataLoadOptions, but couldn’t find a way to make that work either.

I could just change the InvoiceUsers property getter, but then it’d get overwritten every time the dbml gets changed.

Am I just out of luck 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-05-25T17:30:45+00:00Added an answer on May 25, 2026 at 5:30 pm

    I’ll put in my solution here, but still hope someone can come up with something better.

    I’m using LINQ to SQL templates for T4 to generate the code. I went into the .tt file for this particular .dbml file and found the portion that generates the properties for the relationships. I then hacked in an “if” statement that modified the property if it applied to this particular relationship:

        <#=code.Format(association.MemberAttributes)#><#=association.Type.Name#> <#=association.Member#>
        {
            get {
                <#if(association.Name == "InvoiceUser_Invoice"){#>
                                //HACK IN THE .TT FILE TO ALWAYS INCLUDE THIS CONDITIONAL RELATIONSHIP
                if(IsSignup){return null;}
                <#}#>
                <#if (needsSerializationFlag && serialization) {#>
                if (serializing && !<#=association.Storage#>.HasLoadedOrAssignedValue) {
                    return null;
                }
                <#}#>
                return <#=association.Storage#>.Entity;
            }
    

    This makes the generated code for that particular property come out as desired:

        [Association(Name=@"InvoiceUser_Invoice", Storage=@"_InvoiceUser", ThisKey=@"UID", OtherKey=@"UID", IsForeignKey=true)]
        public InvoiceUser InvoiceUser
        {
            get {
                //HACK IN THE .TT FILE TO ALWAYS INCLUDE THIS CONDITIONAL RELATIONSHIP
                                if(IsSignup){return null;}
                                return _InvoiceUser.Entity;
            }
            set {
                InvoiceUser previousValue = _InvoiceUser.Entity;
                if ((previousValue != value) || (!_InvoiceUser.HasLoadedOrAssignedValue)) {
                    SendPropertyChanging();
                    if (previousValue != null) {
                        _InvoiceUser.Entity = null;
                        previousValue.Invoices.Remove(this);
                    }
                    _InvoiceUser.Entity = value;
                    if (value != null) {
                        value.Invoices.Add(this);
                        _UID = value.UID;
                    }
                    else {
                        _UID = default(int);
                    }
                    SendPropertyChanged("InvoiceUser");
                }
            }
        }
    

    So still a nasty hack, but it at least prevents changes to the .dbml file from removing the needed conditional relationship.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.