score:0
Accepted answer
public class ExistingInitializer : ClearDatabaseSchemaIfModelChanges { protected override void Seed(ExistingContext context) { List orders = new List { new Order { OrderId = 10, Item = "Guitars", Quantity = 2, Id = Guid.NewGuid().ToString()}, new Order { OrderId = 20, Item = "Drums", Quantity = 10, Id = Guid.NewGuid().ToString()}, new Order { OrderId = 30, Item = "Tambourines", Quantity = 20, Id = Guid.NewGuid().ToString() } }; List customers = new List { new Customer { CustomerId = 1, Name = "John", Orders = new Collection { orders[0]}, Id = Guid.NewGuid().ToString()}, new Customer { CustomerId = 2, Name = "Paul", Orders = new Collection { orders[1]}, Id = Guid.NewGuid().ToString()}, new Customer { CustomerId = 3, Name = "Ringo", Orders = new Collection { orders[2]}, Id = Guid.NewGuid().ToString()}, }; foreach (Customer c in customers) { context.Customers.Add(c); } base.Seed(context); } }
Source: stackoverflow.com
Related Query
- How to reinsert data from one table onto itself using LINQ in code migration?
- How to Get data in repeater from multiple table using like linq query
- How do you populate a parent child data structure from XML where generic List<> objects are in parent and child structures using one LINQ query?
- how to fetch data from database using linq query for relationship 1:N and N:N (between 3 entity) in asp.net mvc EF code first?
- How to update Linq result with in the list, without assign other data table process itself get another one result
- how to select records from multiple table with max count value from one table using Linq in Asp.net MVC C#
- Linq to select data from one table not in other table
- How does linq actually execute the code to retrieve data from the data source?
- How to include one specific row from another table with LINQ to Entities
- how delete more than one record from database using Linq in asp.net mvc
- Using LINQ how do I create a List of one particular field of an entity from a collection entities
- How to select all columns plus a custom one from table by using EF LINQ?
- Eliminate comma(,) from a column of a Data Table using LINQ
- How to join two table from two different edmx using linq query
- Pull data from multiple tables in one SQL query using LINQ and Entity Framework (Core)
- Get only one value from the table using LINQ
- Using LINQ to copy data from one list to another
- Linq query how to select last one week data from today's date
- Read data from more than one table using Azure Mobile Services
- How to return values from a LINQ query and display them in a table using C#, ASP.NET MVC and Entity Framework
- Using Linq to extract data from a Table
- How to group table data and sum by multiple columns using LINQ or another approach
- how take data from xml using linq to xml
- how to get max id from a table using linq
- How to use c# to perform summing data with type conversion from SQL using LINQ
- How to find the top number between a range given a value from a table using LINQ
- How to sort data loaded from a file using LINQ
- remove rows from data table using LINQ
- How to get linq to transform data from one form to another
- How to fetch limited rows from a table using linq
More Query from same tag
- How to find first N items with Min values using LINQ
- Getting the field names from a Linq To Sql object
- How to check if all values in an array are equal
- Return an empty model when Linq query has no record
- "".All(char.IsNumber) Returns True
- Extend SubSonic's IQueryable Structure (via LINQ?)
- IEnumerable<T> InvalidCastException
- Returning multiple values from a Group by LINQ statement C#
- Entity Framework Code-First Aproach and ModelValidationException
- Reading XML Enumeration yielded no results
- Grouping and nesting list with LINQ
- How can I build linq OR condition base on a list which length is not fixed
- Is there something like `continue` to bypass or skip an iteration of query in LINQ?
- Linq 2 SQL Sum using lambda and handling nulls
- how to fetch data from Func using generic list and linq
- Error creating DataBase with Linq to SQL
- Does order of conditions under where clause in a LINQ query matter
- Parsing SOAP response with LINQ to XML - how to get nested nodes under parent?
- How to get only the date value from DateTime and count it?
- Linq ToDictionary returns an anonymous type
- ASP MVC Paging with LINQ?
- SingleOrDefault in F#
- How do i make .Include to work on an IEnumerable
- Trying to sort IQueryable by dynamic properties
- Multiple Left Joins and dynamic where
- How to get all rows but specifc columns from a DataTable?
- c# linq nested "conditional/composite" grouping
- XDocument containing namespaces
- Combine Parent and Child Lists into a single nested Parent List
- LINQ doing individual queries when it should have the data