Link to home
Start Free TrialLog in
Avatar of RBS
RBS

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Darrell Porter
Darrell Porter
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RBS
RBS

ASKER

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.
How are you connecting to the database? Entity Framework or Linq to SQL or other?
Avatar of RBS

ASKER

Thanks - Guid.newguid() was the answer - sorry I didn't see this earlier.

RBS