-
Notifications
You must be signed in to change notification settings - Fork 1
Creating POCO classes
Eros Stein edited this page Jan 6, 2017
·
3 revisions
- Right-click your POCO project and select
Add > New Item
- Select Blayer and choose POCO
- Name your POCO class
Once you've done that a new file is created with the name you provided and this code:
using Blayer.Data;
using System.ComponentModel.DataAnnotations.Schema;
namespace Your.Namespace.Poco
{
[Table("", Schema = "")]
public class State : EntityBase
{
/// <summary>
/// Id
/// </summary>
public int StateId { get; set; }
}
}
The only thing you need to do now is add your table's name inside the Table
parameter and set its schema using the Schema
property. You can also add the fields that represent your table. The code would be something like this:
using Blayer.Data;
using System.ComponentModel.DataAnnotations.Schema;
namespace Your.Namespace.Poco
{
[Table("States", Schema = "MySchema")]
public class State : EntityBase
{
/// <summary>
/// Id
/// </summary>
public int StateId { get; set; }
/// <summary>
/// State's name
/// </summary>
public string Name { get; set; }
/// <summary>
/// Country ID
/// </summary>
public int CountryId { get; set; }
/// <summary>
/// Country
/// </summary>
[ForeignKey("CountryId")]
public virtual Country Country { get; set; }
}
}
With that we're done with this section.