ASP.NET MVC4: How do I keep from having multiple identical results in my lookup tables
Posted
by
sehummel
on Stack Overflow
See other posts from Stack Overflow
or by sehummel
Published on 2012-12-05T23:01:49Z
Indexed on
2012/12/05
23:03 UTC
Read the original article
Hit count: 208
asp.net-mvc
|entity-framework
I'm new to ASP.NET so this may be an easy question. I'm seeding my database with several rows of dummy data. Here is one of my rows:
new Software { Title = "Microsoft Office", Version = "2012", SerialNumber = "12346231434543", Platform = "PC", Notes = "Macs really rock!", PurchaseDate = "2011-12-04", Suite = true, SubscriptionEndDate = null, SeatCount = 0, SoftwareTypes = new List<SoftwareType> { new SoftwareType { Type="Suite" }}, Locations = new List<Location> { new Location { LocationName = "Paradise" }}, Publishers = new List<SoftwarePublisher> { new SoftwarePublisher { Publisher = "Microsoft" }}}
But when I do this, a new row is created for each location, with the LocationName being set in each row like this. We only have two locations. How do I get it to create a LocationID property for the Software class and in my Locations class. Here is my Location class:
public class Location
{
public int Id { get; set; }
[Required]
[StringLength(20)]
public string LocationName { get; set; }
public virtual Software Software { get; set; }
}
I have this line in my Software class to reference this table:
public virtual List<Location> Locations { get; set; }
Again, what I want when I am done is a Locations table with two entries, and a LocationID field in my Software table. How do I do this?
© Stack Overflow or respective owner