1

I am using linq to SQL , I have two problems.

this is a snap shot from my DBML file enter image description here

first one :- in WorkflowInstance table when i call WFTypeID property or any relationship its give me the int? field not the object , not like in ApplicationForm table its working fine. i check the designer.cs file , its keep defining them System.Data.Linq.Mapping.ColumnAttribute not System.Data.Linq.Mapping.AssociationAttribute any idea why this is happening to some tables and some not ?!

second issue :- some tables have 1:N relations and some 1:1 relation. all tables displaying the relationship as EntityRef or EntitySet. why its not giving me a single object. or this is a normal behavior ?!

2 Answers 2

2

1: LINQ-to-SQL exposes a dual API: foreign keys are often presented both in their raw form, and as the object form. So I would fully expect WFTypeID to be an int? or similar. The interesting questions is: is there also a WFType property? If not, you might want to check the association properties. Click on the dotted line, and look at the Child / Parent properties, and check the Cardinality.

2: it is normal for the backing field in a {0|1}-* relationship to be EntityRef<T>, however - the public API generated by LINQ-to-SQL should be just the T; for example:

[global::System.Data.Linq.Mapping.AssociationAttribute(Name="AssociationName", Storage="_User", ThisKey="UserId", OtherKey="Id", IsForeignKey=true)]
[global::System.Runtime.Serialization.DataMemberAttribute(Order=7, EmitDefaultValue=false)]
public User User
{
    get
    {
        if ((this.serializing 
                    && (this._User.HasLoadedOrAssignedValue == false)))
        {
            return null;
        }
        return this._User.Entity;
    }
    set
    {
        if ((this._User.Entity != value))
        {
            this.SendPropertyChanging();
            this._User.Entity = value;
            this.SendPropertyChanged("User");
        }
    }
}

where the member-name comes from the association's "Parent Property" > "Name":

enter image description here

Note that _User is EntityRef<User>, but the public property User is of type User.

Sign up to request clarification or add additional context in comments.

4 Comments

thx marc for you replay,, can I force linq to generate an object instead of int? WFTypeID ?! And yes it have properties , but how i can use them ,, i tried to instantiate an new object but i could not find the property ...
@BakriBasha so parent property exists? If the parent property is named "Foo", it should just be via .Foo
yes it exists , but when i cant find it in the object ,, i searched for it in the DBML.Designer.cs , in mapped table class also not exist there ,, i am thinking of generating the classes using SPMETAL and replace the one in designer.cs ,, can you advice me in this before i do the effort !?
@BakriBasha it should be in the .designer.cs; unfortunately, it is hard to say more
0

first issue: WFTypeID field is representing a foreign key and I guess your primary keys are integers; it is normal to return integers.

second issue: if the relation is 1 to 1; you will get an EntityRef object representing the object on the other end of the relation. If the relation is 1:N, you will get an EntitySet representing the objects on the other hand. This is normal behaviour, in a one to many relation, one entity will map to "many" entities, not a single object.

1 Comment

Thanks daryal for your efforts, All my tables have int primary key , can you please explain why in some tables have a context object instead of the ID property !!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.