Closed we-apon closed 5 years ago
Hello @we-apon ,
I might be wrong but I believe you need to comment
the UnintentionalCodeFirstException
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//throw new UnintentionalCodeFirstException();
}
It's true that you are database first, but Effort is a memory provider and table/relation must be created as Code First does.
Let me know if that successfully answer your question
Best Regards,
Jonathan
@JonathanMagnan thanks for answer.
Well, it works, if comment exception.. kind of.
At first - it wants some [key]
attrubute on primary key columns of tables, there key column not named like Id
or EntityId
, or key is composite.
And also, my model contains couple of classifier- tables with Integer Ids. EF, by default, treats integer Id as autoincrement column with identity(1, 1), so constant Ids on that tables are transformed into sequential numbers on inserts. This maybe my mistake to use primary keys as constants.
It's easy to add all needed attributes through T4 template, but it seems kind a mess. It will become CodeFirst model, created through ModelFirst approach.
But, for now it works, so really thank you.)
Yup that will be a mess ;)
I would recommend you to use fluent API instead to set everything instead of DataAnnotations
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<KeyValuePair>().HasKey(x => x.Key);
base.OnModelCreating(modelBuilder, null);
}
So you will only affect Effort
and never the model generated.
Yeah)
My bad, I forgot about that fluent api
still hate code first after two years with nHibernate
lol ;)
I love code first for quick testing or debug such as our case when someone submits a bug.
But I always prefer to create the database myself for real application.
I will close this request since it seems answered but feel free to create a new one if you need more information.
Best Regards,
Jonathan
Hi. Sory for bad english and maybe for issue on wrong project.
I've trying to use Z.EntityFramwrodk.Classic.Effort in test project with an DbFirst model and
<TargetFramework>net462</TargetFramework>
, but can't get any luck with it. Once DbContext created - it goes with CodeFirst way and throws standardUnintentionalCodeFirstException
.I've tried it as in documentation example, like:
But, at least in documentation, there is no any way to specify some *.edmx model. It seems to me - there need to call
EntityFrameworkManager.UseDatabaseFirst("SomeModel.edmx")
like in .netstandard2.0 target, but this method is missed in net45 target library of Z.EntityFramework.Classic