orchard_custom_data_access_template
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
orchard_custom_data_access_template [2014/12/18 21:23] – created stephen | orchard_custom_data_access_template [2017/01/01 20:05] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 2: | Line 2: | ||
Assuming the module = Module.Name | Assuming the module = Module.Name | ||
+ | |||
+ | Notes: | ||
+ | |||
+ | - Don't use a SQL reserved word for any of the columns names, e.g. ' | ||
===== Create the models ===== | ===== Create the models ===== | ||
Line 8: | Line 12: | ||
<code c#> | <code c#> | ||
- | namespace Module.Name.Models | + | namespace Module.Name.Models { |
- | { | + | public class CustomerRecord { |
- | public class CustomerRecord | + | |
- | | + | |
public virtual int Id { get; set; } | public virtual int Id { get; set; } | ||
Line 20: | Line 22: | ||
} | } | ||
| | ||
- | public class OrderRecord | + | public class OrderRecord { |
- | | + | |
public virtual int Id { get; set; } | public virtual int Id { get; set; } | ||
Line 34: | Line 35: | ||
} | } | ||
- | public class OrderItemRecord | + | public class OrderItemRecord { |
- | | + | |
public virtual int Id { get; set; } | public virtual int Id { get; set; } | ||
Line 47: | Line 47: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | ===== Create the migration ===== | ||
+ | |||
+ | Notes: | ||
+ | |||
+ | * Yes, you **have** to use the ' | ||
+ | * To determine the current migration number is, run '' | ||
+ | * TODO: Why no foreign keys? | ||
+ | |||
+ | <code c#> | ||
+ | namespace Module.Name { | ||
+ | public class DatabaseMigrations : DataMigrationImpl { | ||
+ | |||
+ | public int Create() { | ||
+ | SchemaBuilder.CreateTable(typeof(CustomerRecord).Name, | ||
+ | table => table | ||
+ | .Column< | ||
+ | .Column< | ||
+ | .Column< | ||
+ | ); | ||
+ | |||
+ | SchemaBuilder.CreateTable(typeof(OrderRecord).Name, | ||
+ | table => table | ||
+ | .Column< | ||
+ | .Column< | ||
+ | .Column< | ||
+ | .Column< | ||
+ | .Column< | ||
+ | ); | ||
+ | | ||
+ | SchemaBuilder.CreateTable(typeof(OrderItemRecord).Name, | ||
+ | table => table | ||
+ | .Column< | ||
+ | .Column< | ||
+ | .Column< | ||
+ | .Column< | ||
+ | .Column< | ||
+ | ); | ||
+ | |||
+ | return 1; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
orchard_custom_data_access_template.1418937833.txt.gz · Last modified: 2017/01/01 19:50 (external edit)