Unique Constraint doesn't work

Posts   
 
    
klausb
User
Posts: 6
Joined: 20-Nov-2006
# Posted on: 20-Nov-2006 21:48:27   

Hi

I'm using SQL Server 2000 and LLBLGen Pro V1.0.2005.1 Final

I have a table with a primary key and a field for storing an email adress. I want to be able to fetch an entity from this table by given an email adress as parameter, but after having created a unique constraint on the field, I can see that LLBLGen notices the change, but I am still not able to use email as parameter when fetching an entity.

Can anyone help me out with this?

Regards, KlausB

PilotBob
User
Posts: 105
Joined: 29-Jul-2005
# Posted on: 20-Nov-2006 21:53:49   

Did you make it a unique constraint or unique index? I think in one circumstance a method is created automaticlly for you, in the other it isn't.

BOb

klausb
User
Posts: 6
Joined: 20-Nov-2006
# Posted on: 20-Nov-2006 21:59:14   

If I look up the "IX_Lead" constraint with query analyzer it shows me that the xtype = UQ, so I believe that it should be a unique constraint, right?

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 21-Nov-2006 02:30:38   

Can you post the code that is not working and whether you are using SelfServicing or Adapter?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 21-Nov-2006 09:27:09   

klausb wrote:

If I look up the "IX_Lead" constraint with query analyzer it shows me that the xtype = UQ, so I believe that it should be a unique constraint, right?

Indeed UQ is a unique constraint... odd. If you open catalog explorer in the designer, browse to the table do you see a '1' under unique constraints in the detail view pane ?

Frans Bouma | Lead developer LLBLGen Pro
klausb
User
Posts: 6
Joined: 20-Nov-2006
# Posted on: 21-Nov-2006 21:53:25   

bclubb wrote:

Can you post the code that is not working and whether you are using SelfServicing or Adapter?

I'm using self-servicing.

Here is the code, that wont build:

    public static void BekraeftLead(string email, string ip)
    {

--------->>>>> LeadEntity entity = new LeadEntity(email);

        if (entity.Fields.State == EntityState.Fetched)
        {
            entity.Confirmed = true;
            entity.Ip = ip;
        }
        else
        {
            entity = new LeadEntity();
            entity.Email = email;
            entity.Ip = ip;
            entity.Confirmed = true;
        }

        return;
    }

Error: Argument '1': cannot convert from 'string' to 'int'

It will only accept the PK of Lead which ofcourse is of type int.

klausb
User
Posts: 6
Joined: 20-Nov-2006
# Posted on: 21-Nov-2006 21:58:43   

Otis wrote:

klausb wrote:

If I look up the "IX_Lead" constraint with query analyzer it shows me that the xtype = UQ, so I believe that it should be a unique constraint, right?

Indeed UQ is a unique constraint... odd. If you open catalog explorer in the designer, browse to the table do you see a '1' under unique constraints in the detail view pane ?

If I access the Unique Constraint viewer for table "Lead", then I can see the IX_Lead with the Email field below, so it should be there as far as I can figure it out.

One thing though, that may be important is, that when I open my project, I get an error message:

"Couldn't find assembly 'mscorlib.resources, Version=1.0.5000.0, Culture=da-..."

And it wants me to find the file manually - I click cancel twice and can continue with refreshing project and so on...

Perhaps resolving this issue could correct the problem - do you now how to resolve it?

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 22-Nov-2006 02:05:31   

You don't use the constructor to load an entity using the unique constraint. The constructor only functions with PKs. To load an entity using a unique constraint is self servicing you should have a new method that you can use that would look essentially like this.

LeadEntity entity = new LeadEntity();
entity.FetchUsingUCEmail(email);

klausb
User
Posts: 6
Joined: 20-Nov-2006
# Posted on: 22-Nov-2006 21:13:37   

bclubb wrote:

You don't use the constructor to load an entity using the unique constraint. The constructor only functions with PKs. To load an entity using a unique constraint is self servicing you should have a new method that you can use that would look essentially like this.

LeadEntity entity = new LeadEntity();
entity.FetchUsingUCEmail(email);

Thank you all for your dedicated help. I'm sorry I didn't catch this one to begin with.