I'm using Entity Framework v4, Code Fi开发者_StackOverflow中文版rst. I'm decorating the property that corresponds to the primary key with KeyAttribute, as so: [Key].I want to be able to set this property explicitly instead of having it autoincrement. thanks
Change the type to a string, that should take care of the auto-increment issue.
Edit: Just in response to your wanting to use an SSN as the primary key, I would advise against storing an SSN as plain-text in your database. Unless you have an overwhelming need to do it and have some pretty tight security in place I would recommend encrypting it before placing it in the database. There are lots of legal ramifications to exposing SSNs, and plain text SSNs in a database is asking for identity theft attempts ;)
You might try:
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int fookey {get;set;}
Take a look at the DatabaseGeneratedOption Enumeration.
精彩评论