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 can I access this in C#?
- Query a Javascript Object (graph)
- LINQ query to turn few items in list as checked
- Replacing last characters with a character
- Creating class objects using LINQ with a highly nested XML
- Dynamically build IQueryable OR Statement
- Fetch value of element by attribute using linq to xml
- LINQ: How to get parent types' properties while getting their children collections
- Group lines of log-file using Linq
- how to select common elements according to the value of a property?
- find elements of different types in two lists with common property value, linq variant of two for each loops
- SQL to linq query that uses local List<DateTime> as one of the "tables"
- How can I order by multiple columns using the IQueryable in Cosmos DB?
- Execute method within linq
- Searching a List of objects in an object list using linq in VB.net
- linq to return associated object types
- LINQ join in lambda with most recent date
- "System.ArgumentNullException: Value cannot be null" in MVC 3
- Where is the code for the EDML generated Models?
- LINQ to objects cast result of query
- Using method parameter as generic type argument
- How can I Select an IEnumerable over 2 Tables using LINQ
- LINQ to DataSet Group By Multiple Columns - Method Syntax
- How to convert a SQL with multiple left joins to an Entity Framework LINQ statement using Include methods (No Join methods)?
- Using LINQ to Update A Property in a List of Entities
- Select distinct list from nested collections on multiple fields
- How to get a Lookup as Union of 2 old Lookups?
- Fastest way Calculating Sum of Customers' Orders using Linq
- VB.Net Sort a List using property name
- Dynamic filtering, impossible to get property name dynamically entity framework