Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> See if specific data exsits
 

Pages: 1
LLBLGen Pro Runtime Framework
See if specific data exsits
Page:1/1 

  Print all messages in this thread  
Poster Message
jlazanowski
User



Location:

Joined on:
20-Sep-2006 16:14:39
Posted:
22 posts
# Posted on: 16-Oct-2006 23:22:42.  


I'm trying to create a helper function that will see if a record similar to the one that a user is about to add already exists.

In my model there may be cases where the user is allowed to enter another contact with the same First, Last and Company Name but I want to see if one exists and flag the user first.

So what is a good way to go about this, the way I have it setup looks like this

Code:


EntityField2 _companyName = ContactFields.CompanyName;
            EntityField2 _firstName = ContactFields.FirstName;
            EntityField2 _lastName = ContactFields.LastName;
            PredicateExpression filter = ((_companyName == _testContact.CompanyName.ToString()) & (_firstName == _testContact.FirstName) &
                                            (_lastName == _testContact.LastName));
            //EntityCollection<ContactEntity> _contacts = new EntityCollection<ContactEntity>(new ContactEntityFactory());
            ContactEntity _contacts = new ContactEntity();
            using (DataAccessAdapter _adapter = new DataAccessAdapter())
            {
                _adapter.FetchEntityUsingUniqueConstraint(_contacts, filter);
            }


this works, but I'm not sure that it's ideal?

Anyone else do something similar? Also assuming this way is the right way, how do you test for null, the _adapter fills all the fields with an out of sync exception.

Any thoughts?

  Top
bclubb
User



Location:
Norman, Oklahoma
Joined on:
12-Feb-2004 22:18:04
Posted:
934 posts
# Posted on: 17-Oct-2006 01:56:09.  
Well if you have a uniqueconstraint defined for Company Name, First Name, and Last Name then I'm not sure how you could insert a duplicate. I would essentially do what you are doing though assuming that you could have records with duplicate company name, first name, and last name. I would use adapter.FetchCollection() and pass a filter with the smilarities that you are looking for then display these to the user.

If you want to check for null try something like this

Code:
bucket.PredicateExpression.Add((OrderFields.OrderDate==System.DBNull.Value));


  Top
jlazanowski
User



Location:

Joined on:
20-Sep-2006 16:14:39
Posted:
22 posts
# Posted on: 17-Oct-2006 03:12:50.  
bclubb wrote:
Well if you have a uniqueconstraint defined for Company Name, First Name, and Last Name then I'm not sure how you could insert a duplicate. I would essentially do what you are doing though assuming that you could have records with duplicate company name, first name, and last name. I would use adapter.FetchCollection() and pass a filter with the smilarities that you are looking for then display these to the user.

If you want to check for null try something like this

Code:
bucket.PredicateExpression.Add((OrderFields.OrderDate==System.DBNull.Value));



The constraint isn't there, I'm just not sure how to pass in a predicate expression to see if a record with those attributes (first, last, company) exist.

I would like to do this with a collection (you'll notice i've got one commented out in my original post), however FetchEntityCollection takes a relationobject not a IPredicateExpression. If I can do this on a collection, that's the way I want to do it.

Also when I refered to checking for null, I was refering to the entity object. Since the adapter will fill fields with exceptions I can't say
Code:

if(_myEntity != null)
{}


A collection solves the problem since I can get a count.

TIA,
Justin
  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14569 posts
# Posted on: 17-Oct-2006 07:42:35.  
Please try the following code, and then check for the collection count.

Code:

RelationPredicateBucket bucket = new RelationPredicateBucket();
bucket.PredicateExpression.Add(ContactFields.CompanyName == _testContact.CompanyName.ToString());
bucket.PredicateExpression.Add(ContactFields.FirstName == _testContact.FirstName);
bucket.PredicateExpression.Add(ContactFields.LastName == _testContact.LastName);

EntityCollection<ContactEntity> _contacts = new EntityCollection<ContactEntity>(new ContactEntityFactory());
using (DataAccessAdapter _adapter = new DataAccessAdapter())
{
        _adapter.FetchEntityCollection(_contacts, bucket);
}


  Top
jlazanowski
User



Location:

Joined on:
20-Sep-2006 16:14:39
Posted:
22 posts
# Posted on: 17-Oct-2006 14:23:59.  
That does the trick, Thank You!

Just a quick side question to this, based on the following should I assume that a RelationPredicate isn't always a relationship?

  Top
Jessynoo
Support Team



Location:
Lyon, France
Joined on:
19-Aug-2004 06:39:28
Posted:
296 posts
# Posted on: 17-Oct-2006 15:25:31.  
Hi,

a RelationPredicateBucket is a structure the stores both the relation collection and the predicate expression your query is based on.

In your case, there is no relation needed, only the predicate part of it.


Jesse
LLBLGen Pro Support Team
 
Top
mihies
User



Location:
Nova Gorica, Slovenia
Joined on:
29-Jan-2006 16:00:15
Posted:
799 posts
# Posted on: 18-Oct-2006 10:17:39.  
I would rather suggest doing SELECT COUNT() FROM ... WHERE ... (translated to LLBLGenPro syntax of course)
instead of populating collection. As populating a collection it is an overkill if you don't need that data.
Miha Markic
MVP C#, LLBLGenPro Partner, DXSquad
Blog, Twitter
 
Top
rtbike
User



Location:
Mill Valley, CA
Joined on:
23-Jan-2009 01:59:46
Posted:
23 posts
# Posted on: 31-Jan-2009 00:23:23.  
I see this is a old post but i will try here first as this is relivant to the topic.

Using self service how would you do the select count()?

The documentation is a bit confusing, i am only a few weeks into LLBL Gen Pro but working on a large project using it and I am on the learning curve but also under some time constraints.

In the documentation I tried using the Result set fields this seems to make sence to me but it is not working, I know I am missing something

        ResultsetFields checkForCart = new ResultsetFields(1);
        checkForCart.DefineField(CartFieldIndex.UserId, 0, UserID.ToString());
        checkForCart[0].AggregateFunctionToApply = AggregateFunction.Count;


  Top
daelmo
Support Team



Location:
Guatemala City
Joined on:
28-Nov-2005 23:35:24
Posted:
8098 posts
# Posted on: 31-Jan-2009 08:55:20.  
Hi rtbike. Use DynamicLists for more complex or custom data you want to fetch. For simple counts, do this Regular Smiley :
Code:

OrderCollection orders = new OrderCollection();
int numberOfOrders = orders.GetDbCount();

int numerOfOrdersFromALFKI = orders.GetDbCount(OrderFields.CustomerId == "ALFKI");

int numberOfOrdersFromCustomersInGuatemala = orders.GetDbCount(CustomerFields.City == "GTM",
    new RelationCollection(OrderEntity.Relations.CustomerEntityUsingCustomerId));


P.S. Next time please open a new thread Wink
David Elizondo
LLBLGen'ing (articles and code snippets) | linkedin | twitter
 
Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.