Relation Between Two Table

Posts   
 
    
Posts: 97
Joined: 29-Apr-2009
# Posted on: 31-Jul-2009 05:10:27   

Hello All,

i have one table : Payment & second table :user

In Payment Table, i have following fields PaymentID->PK PaymentMode CreditCardType CreditCardNumber CreditCardExpiryDate PaidAmount PaidBy->this will be store UserID PaidTo->this will be store UserID

In User Table, i have followinf fields UserID->PK UserName First Name Last Name

Now i have bind my gridview by payment collection,it will display all data in gridview, in that i have display FirstName & Last Name of User (i.e. by UserID in PaidBy & PaidTo) see below Image

My Problem is here : i want to search by first name & Last name but in payment table there is user id,not first name & last name, so how can i achieve this in LLBLGen..

any code can you provide please....

Thanks you in advanced

i want to search

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 31-Jul-2009 06:33:56   

You just need to create a filter that specify the userFields you want to filter and include the involved relation.

How your search button code looks like? Are you using Adapter or SelfServicing? Are you using LLBLGeProDataSource?

David Elizondo | LLBLGen Support Team
Posts: 97
Joined: 29-Apr-2009
# Posted on: 31-Jul-2009 08:20:38   

daelmo wrote:

You just need to create a filter that specify the userFields you want to filter and include the involved relation.

How your search button code looks like? Are you using Adapter or SelfServicing? Are you using LLBLGeProDataSource?

Hi daelmo,

Thanks for reply

well i am using self services

My Search code looks like below


public PaymentCollection ClaPayment = new PaymentCollection();
ClaPayment.GetMulti(null);
PredicateExpression JobFilter = new PredicateExpression();
IPredicateExpression filter = new PredicateExpression();
filter.Add(new FieldLikePredicate(PaymentFields.PaidBy, "%" + txtSearch.Text + "%"));
JobFilter.Add(filter);
ClaPayment.GetMulti(JobFilter);
intCount = 0;
gvCreditCardPayment.DataSource = ClaPayment;
gvCreditCardPayment.DataBind();


here in PaymentFields.PaidBy, paid by is user id, i need to search on firstname & last name which is in user table.

so how can i achieve this??

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 31-Jul-2009 10:19:01   

public PaymentCollection ClaPayment = new PaymentCollection(); ClaPayment.GetMulti(null);

Why do you call getMulti here? it will fetch the entire table without filtering.

PredicateExpression JobFilter = new PredicateExpression(); IPredicateExpression filter = new PredicateExpression();

Why do you use 2 predicate expressions, no need for that.

filter.Add(new FieldLikePredicate(PaymentFields.PaidBy, "%" + txtSearch.Text + "%"));

As Daelmo said, you should filter on the fields of the User table, and use a relation between both entities.

Your code should look like the following: (not tested).

public PaymentCollection ClaPayment = new PaymentCollection();

IPredicateExpression filter = new PredicateExpression();
filter.Add(new FieldLikePredicate(UserFields.FirstName, "%" + txtSearch.Text + "%"));
filter.AddWithOr(new FieldLikePredicate(UserFields.LastName, "%" + txtSearch.Text + "%"));

IRelationCollection relations = new RelationCollection();
relations.Add(PaymentEntity.Relations.UserEntityUsingPaidBy); // not sure about the relation name, intellisense should guide you.

ClaPayment.GetMulti(JobFilter, relations);

gvCreditCardPayment.DataSource = ClaPayment;
gvCreditCardPayment.DataBind();
Posts: 97
Joined: 29-Apr-2009
# Posted on: 01-Aug-2009 06:11:42   

Walaa wrote:

public PaymentCollection ClaPayment = new PaymentCollection(); ClaPayment.GetMulti(null);

Why do you call getMulti here? it will fetch the entire table without filtering.

PredicateExpression JobFilter = new PredicateExpression(); IPredicateExpression filter = new PredicateExpression();

Why do you use 2 predicate expressions, no need for that.

filter.Add(new FieldLikePredicate(PaymentFields.PaidBy, "%" + txtSearch.Text + "%"));

As Daelmo said, you should filter on the fields of the User table, and use a relation between both entities.

Your code should look like the following: (not tested).

public PaymentCollection ClaPayment = new PaymentCollection();

IPredicateExpression filter = new PredicateExpression();
filter.Add(new FieldLikePredicate(UserFields.FirstName, "%" + txtSearch.Text + "%"));
filter.AddWithOr(new FieldLikePredicate(UserFields.LastName, "%" + txtSearch.Text + "%"));

IRelationCollection relations = new RelationCollection();
relations.Add(PaymentEntity.Relations.UserEntityUsingPaidBy); // not sure about the relation name, intellisense should guide you.

ClaPayment.GetMulti(JobFilter, relations);

gvCreditCardPayment.DataSource = ClaPayment;
gvCreditCardPayment.DataBind();

hi walaa,

thanks for such good guild line.My Database is MySQL, well i have review your code, i understand entire code but i dont understand one thing is that


 relations.Add(PaymentEntity.Relations.UserEntityUsingPaidBy); // not sure about the relation name, intellisense should guide you.

when i put dot(.) after relations word i can get only following property

Equal GetAllRelation getHasCode getSubtyperelation GetSuperTypeRelation GetType ToString

not any replation between table. how to do that ?? and i dont understand your comment "not sure about the relation name, intellisense should guide you."

Please help me for this problem

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 03-Aug-2009 07:27:01   

Just be sure this line is correct, when you add the relation:

relations.Add(PaymentEntity.Relations.UserEntityUsingPaidBy);
David Elizondo | LLBLGen Support Team
Posts: 97
Joined: 29-Apr-2009
# Posted on: 03-Aug-2009 07:32:24   

daelmo wrote:

Just be sure this line is correct, when you add the relation:

relations.Add(PaymentEntity.Relations.UserEntityUsingPaidBy);

Hi daelmo,

thanks for reply

see this image, i am getting like this

www.freeimagehosting.net/uploads/7ba410f78a.png

no relationship is available . i want to know how to add relationship, so as per walaa's code work for me.

Posts: 97
Joined: 29-Apr-2009
# Posted on: 03-Aug-2009 08:30:11   

daelmo wrote:

Just be sure this line is correct, when you add the relation:

relations.Add(PaymentEntity.Relations.UserEntityUsingPaidBy);

Thanks daelmo

it done. i have add relationship from LLBLGui