MVC - Automatically Generate GUID for Id field

Hi:

A have an MVC application in which I have the following class:

 public class Actor
{
	public Actor(Guid id, string name)
	{
		Id = id;
		Name = name;
	}

	public Guid Id { get; set; }
	public string Name { get; set; }
}

Open in new window


I would like to make it so that:

1.

when I create an actor, the guid is generated automatically - as in an identity field

2.

I can seed the database with 3 names -
Any help greatly  appreciated

RBS
RBSAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Darrell PorterConnect With a Mentor Enterprise Business Process ArchitectCommented:
Have you tried guid.newguid()?

See
stackoverflow.com/questions/16195863/c-sharp-generate-guid-that-is-uniquedoes-not-exist-in-a-table-in-the-database
For an example
0
 
RBSAuthor Commented:
Thank you but this does not deal with either of my questions - namely how to generate a guid automatically and how to seed a database with three records that use a guid as an id.
0
 
Fernando SotoRetiredCommented:
How are you connecting to the database? Entity Framework or Linq to SQL or other?
0
 
RBSAuthor Commented:
Thanks - Guid.newguid() was the answer - sorry I didn't see this earlier.

RBS
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.