1

I m new about this topic (code first development). I want to do relationship between asp.net default User table and my class (one-to-one).

  1. Is this possible.
  2. if this is possible.How I can do it.Should I write User class, too? or any way.

Could you give me a starting point? My class is like below.

public class Customer
{
    [Key]
    public int customer_id { get; set; }
    public string customer_name{ get; set; }
    public string user_id

    public virtual User User{ get; set; }
}

I hope, I have explained :)

Thanks.

AliRıza Adıyahşi
  • 15,658
  • 24
  • 115
  • 197

1 Answers1

1

If I undestand correctly - yes, you shoul write all the classes what you want to use in youre code, even if thay exist in the database. Here some tutorial, maybe it can help's you http://codefirst.codeplex.com/

Igor Konopko
  • 764
  • 2
  • 13
  • 26
  • +1. But It sounds like it can do. I should not write. There should be an option. Because, I can get asp.net default tables model in my project. And I can use it. Could you look this : http://stackoverflow.com/questions/6021135/ef-code-first-1-to-1-optional-relationship – AliRıza Adıyahşi Jul 06 '12 at 06:25
  • look's here, if you want to make relative databese with your database and asp mvc membership it shold help's http://stackoverflow.com/questions/6447313/how-do-i-integrate-membership-tables-with-entity-framework-asp-net – Igor Konopko Jul 06 '12 at 06:45
  • I think I could not explain :) sorry problem is my explanation. I can use User class without writting. I m new sorry, If I did not see an example exactly the same, I wont understand. Thanks for attention. – AliRıza Adıyahşi Jul 06 '12 at 07:29
  • Your User Class was created with new MVC project? In that case it's call membeship provider, what is default in asp mvc. But if User is some table which was creadet by you in your datebase, than you shold write User Class in your code. – Igor Konopko Jul 06 '12 at 07:44
  • Yes. It created when I configure the users and roles with asp.net configuraiton.Users,Roles,UserInRoles, etc. These are allready exist in my database with entity provider. – AliRıza Adıyahşi Jul 06 '12 at 07:52
  • And I dont want to write these classes again :) – AliRıza Adıyahşi Jul 06 '12 at 07:53
  • All that asp.net user configuration are called Membership providers, so all information what you need too read is there http://stackoverflow.com/questions/6447313/how-do-i-integrate-membership-tables-with-entity-framework-asp-net – Igor Konopko Jul 06 '12 at 08:40
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/13501/discussion-between-aliriza-adiyahsi-and-igor-konopko) – AliRıza Adıyahşi Jul 06 '12 at 08:55