3

I have a database that is changing a lot and i am constantly having to go into the data context designer and manually set a number of associations child properties to false. Each time i delete the table from the designer i have to go back in and redo all the associations.

Is there a way to use a partial class to define what the association child property is on say an entity called Company which has a one to many relationship to an entity called Program?

My hope is that i can simply change the association child property in code so that each time the entity is removed from the data context and re-added, i dont have to go through the whole process again.

Thanks for any help!

ps_md
  • 209
  • 2
  • 10

2 Answers2

0

I have been watching this question, hoping someone has better news for you than I do. You can in fact add a partial class in the same namespace as your context and within there define new name for the child property/collection (it is so annoying to have it re-generate as User1, User2, User3 when you have defined it as OpenedBy, ApprovedBy and ClosedBy or some similar such thing).

This does help with being able to access the properties by a more friendly name, as you have expressed above; however I have not found a way yet to, in that partial class, define the property such that it maintains all the properties (pun not intended) of Entity Framework navigation properties with full read/write functionality.

It doesn't solve your problem, but as far as I know, it is an accurate answer; I have moved on and just accepted that I will have to rename navigation properties in the EDMX in the case that I have to drop/re-add an entity.

Rick Petersen
  • 734
  • 5
  • 15
  • I did research this for a while and ultimately came to the conclusion that i do "just have to deal with it." The biggest issue is mainly remembering which associations properties were changed so that i can revert them after the entity is dropped and added back. – ps_md Dec 06 '12 at 13:00
  • I agree completely. I end up either keeping an electronic list or screenshots of the edmx designer if the model is small enough to fit legibly within a single screen. – Rick Petersen Dec 06 '12 at 14:43
0

I've got the same problem...and couldn't find a solution either.

However, I have some information for people that are looking into this:

When ChildProperty is set to false, the .designer.cs file is changed (instead of the .dbml/.dbml.layout ones). Here's an example...

ChildProperty=true:

[global::System.Data.Linq.Mapping.AssociationAttribute(Name="bank_account_bank_payment_file", Storage="_bank_account", ThisKey="company_bank_account_id", OtherKey="bank_account_id", IsForeignKey=true)]
public bank_account bank_account
{
    get
    {
        return this._bank_account.Entity;
    }
    set
    {
        bank_account previousValue = this._bank_account.Entity;
        if (((previousValue != value) 
                || (this._bank_account.HasLoadedOrAssignedValue == false)))
        {
            this.SendPropertyChanging();
            if ((previousValue != null))
            {
                this._bank_account.Entity = null;
                previousValue.bank_payment_files.Remove(this);
            }
            this._bank_account.Entity = value;
            if ((value != null))
            {
                value.bank_payment_files.Add(this);
                this._company_bank_account_id = value.bank_account_id;
            }
            else
            {
                this._company_bank_account_id = default(int);
            }
            this.SendPropertyChanged("bank_account");
        }
    }
}

ChildProperty=false:

[global::System.Data.Linq.Mapping.AssociationAttribute(Name="bank_file_handler_bank_payment_file", Storage="_bank_file_handler", ThisKey="bank_file_handler_id", OtherKey="bank_file_handler_id", IsForeignKey=true)]
[global::System.Runtime.Serialization.DataMemberAttribute(Order=17, EmitDefaultValue=false)]
public bank_file_handler bank_file_handler
{
    get
    {
        if ((this.serializing 
                    && (this._bank_file_handler.HasLoadedOrAssignedValue == false)))
        {
            return null;
        }
        return this._bank_file_handler.Entity;
    }
    set
    {
        if ((this._bank_file_handler.Entity != value))
        {
            this.SendPropertyChanging();
            this._bank_file_handler.Entity = value;
            this.SendPropertyChanged("bank_file_handler");
        }
    }
}
Christian
  • 27,509
  • 17
  • 111
  • 155