Mike
Mike

Reputation: 2601

EF Code First 4.3: Migration/Seed

I'm trying to Seed some data in my Migration configuration file. I have created a new instance of the location class

var location = new Location
            {
                Name = "Test",
                Street = "Test",
                City = "Test",
                State = "Test",
                ZipCode = "Test",
                Country = "US",
                PhoneNumber = "Test",
                EmailAddress = null,
                Website ="Test",
                Latitude = Convert.ToDecimal(35.137592),
                Longitude = Convert.ToDecimal(-85.124883)
            };

And to seed it, I have

context.Locations.AddOrUpdate(
                t =>
                new
                    {
                        t.Name,
                        t.Street,
                        t.City,
                        t.State,
                        t.ZipCode,
                        t.Country,
                        t.PhoneNumber,
                        t.EmailAddress,
                        t.Website,
                        t.Latitude,
                        t.Longitude
                    }, location);

Both Latitude and Longitude are decimal? types.

I'm getting the following error when trying to run this migration:

The binary operator Equal is not defined for the types 'System.Nullable`1[System.Decimal]' and 'System.Decimal'.

How do I fix this?

Upvotes: 1

Views: 564

Answers (1)

Mike
Mike

Reputation: 2601

Changed it to

context.Locations.AddOrUpdate(t  => t.Name,location);

So that it only checks against the Name column (string in this instance)

Upvotes: 2

Related Questions