My FK associations are correct in model and code. 

I have bindingsource component on my customer form bind to Customer Entity. 
All the person related fields are mapped to customer. Person and address
related fields are mapped to customer. Address. 

On form load if it an existing customer, I just get that customer as below

          Public ReadOnly Property GetCustomer(ByVal customerId As Integer)
As CUSTOMER 
            Get
                Dim customer As CUSTOMERS =
db.CUSTOMERS.FirstOrDefault(Function(d) d.ID = customerId)
                If Not customer.ADDRESSReference.IsLoaded Then
customer.ADDRESSReference.Load()
                If Not customer.PERSONReference.IsLoaded Then
customer.PERSONReference.Load()
                Return customer
            End Get
          End Property

Or if it is a new customer form then

       Customer = New CUSTOMER
        If Customer.ADDRESS Is Nothing Then
            Customer.ADDRESS = New ADDRESS
        End If
        If Customer.PERSON Is Nothing Then
            Customer.PERSON = New PERSON
        End If

On SaveClose Button Click, If it is a new customer I just call
context.AddToCustomer(customer) or if is an update then I call
context.SaveChanges.


-----Original Message-----
From: Jiri Cincura [mailto:[email protected]] 
Sent: Wednesday, January 20, 2010 5:09 PM
To: For customers and developers of the Firebird .NET providers
Subject: Re: [Firebird-net-provider] Entity Framework Foreign Key Relation

On Wed, Jan 20, 2010 at 18:51, Muthu Annamalai <[email protected]>
wrote:
> a record in customer table using Entity Framework all the PK's were
inserted
> as 0. I searched online and changed all the PK's as Identity column, still
> no luck. See the sample row.

Reading this looks like you're talking about FK. Anyway if you have
proper associations created in your model and code, the EF will do the
FKs for you.

I.e.
Person p = new Person();
p.Name = "...";
p.Role = <some role/new role object>;
context.Persons.Add(p);
context.SaveChanges();

-- 
Jiri {x2} Cincura (CTO x2develop.com)
http://blog.cincura.net/ | http://www.ID3renamer.com

----------------------------------------------------------------------------
--
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for
Conference
attendees to learn about information security's most important issues
through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
Firebird-net-provider mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider
 

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4791 (20100120) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
 

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4791 (20100120) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 


------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
Firebird-net-provider mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider

Reply via email to