Hi, I'm using the Developing step-by-step MPA tutorial to create my own Proof of Concept, the Entity People became Contact etc... A this time, the table is successfully created on DBB SqlServer 2016 with a id type Guid (not long or int). See my my code: public class Contact : FullAuditedEntity<Guid> { public override Guid Id { get; set; }
public Contact()
{
Id = SequentialGuidGenerator.Instance.Create();
}
===================.... ================= This table exists in my BDD, but the task Update-Database doesn't run the Seed process No error, no warning, just a table empty at the end...
using System.Linq; using Lexigone.Loxo_FrontOffice.EntityFramework; using Lexigone.Loxo_FrontOffice.LexDirectory;
namespace Lexigone.Loxo_FrontOffice.Migrations.Seed.Tenants { public class InitialContactCreator { public readonly Loxo_FrontOfficeDbContext _context;
public InitialContactCreator(Loxo_FrontOfficeDbContext context)
{
_context = context;
}
public void Create()
{
var etienne = _context.Contacts.FirstOrDefault( p => p.EmailAddress == "[email protected]");
if(etienne == null)
{
_context.Contacts.Add(
new Contact
{
FirstName = "Etienne",
LastName = "Tronc",
EmailAddress = "[email protected]"
}
);
}
===================================..... ==============================
Can you help me ? Bests Regards. Olivier
3 Answer(s)
-
0
In your EF project, there is a class named MyProjectDbContext.cs, you will find the code shown below. Each time you add new entities, you need to add one line of code as shown.
public class MyProjectNameDbContext : AbpZeroDbContext<Tenant, Role, User> { /* Define an IDbSet for each entity of the application */ public virtual IDbSet<BinaryObject> BinaryObjects { get; set; } public virtual IDbSet<Friendship> Friendships { get; set; } public virtual IDbSet<ChatMessage> ChatMessages { get; set; } //20161103 - Added for My Proj public virtual IDbSet<MyEntity> MyTable { get; set; }
To get the custom seed classes to run you need to update the method, shown below, in EF project. This method is in the Configuration.cs class in the "migrations" folder.
protected override void Seed(EntityFramework.MyProjectDbContext context) { ///Code removed for simplicity //You add this line: new AddressRelated(context).Create(); }
AddressRelated is my seed data class, where I load tables like Country and State.
-
0
Perfect... Nice day :P
-
0
Thanks a lot @exlnt :)