6

I don't want to include relations in my edmx entity framework, I want to have the foreign key field as a normal property in my entity.

How can I do that?

3 Answers 3

1

If you want plain foreign keys in your database then you're using the wrong one. As far as I know entity framework made sure all those obscure id's were thrown away and replaced with pointers to the entity you need. If you really want those foreign keys then you should look into a different database.

Sign up to request clarification or add additional context in comments.

1 Comment

what about using database first approach?
0

http://www.thedatafarm.com/blog/2007/09/11/EntityDataModelAssociationsWheresMyForeignKey.aspx

I found the article describing the error in our ways... basically we never supposed to be querying tables via foreign keys instead take a bit more relational approach

(From o In nw.Orders 
 Where o.OrderID = 10281 
 Select o.Customers
).First

Comments

0

I take it that you're trying to access a table say Contact that has a foreign key SubscriberId in it, now say you want to add a Contact with Foreign key 1, example below instead of hacking away at edmx.

using (BulkSmsEntities ctx = new BulkSmsEntities())
{
    int SubscriberId = 1;
    tb_contact contact = new tb_contact();
    contact.tb_subscriber = ctx.tb_subscriber
        .First(a => a.SubscriberId == SubscriberId);
    ctx.AddTotb_subscriber_contacts(contact);
    ctx.SaveChanges();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.