how to use Logical relation with IRelationCollection ( but physically doesnt exist)

Posts   
 
    
sekorev
User
Posts: 11
Joined: 16-May-2008
# Posted on: 16-May-2008 12:41:15   

Hi,

I have some problems with "Relation" issue.

Lets say that I have 2 db tables named Description , Users Description has 4 columns named :id, userid, source_type, source_id Users has 2 columns named : id, name

Logically Description.userid refers to Users.id but physically there is no relation within database. What i cant do is adding a relation using RelationCollection and bind to datagrid.

My code is as follows

DescriptionsCollection dc = new DescriptionsCollection(); PredicateExpression filter = new PredicateExpression(); filter.Add(DescriptionsFields.SourceId == _id); filter.Add(DescriptionsFields.SourceType == _type); SortExpression sort = new SortExpression(DescriptionsFields.InsertDate | SortOperator.Descending); //IRelationCollection relations = new RelationCollection(); //relations.Add(UsersEntity.Relations.); dc.GetMulti(filter,0,sort); gv.DataSource = dc; gv.DataBind();

note: there is no relation/attribute under UsersEntity.Relations.

arschr
User
Posts: 893
Joined: 14-Dec-2003
# Posted on: 16-May-2008 15:05:42   

In the designer you should be able to manually add this relation as long as the datatypes are the same and id is the primary key of the user table. (Assuming it is 1 user to many descriptions).

sekorev
User
Posts: 11
Joined: 16-May-2008
# Posted on: 16-May-2008 15:15:43   

Hi,

I am still figuring it out. thanks for the help.