Npgsql integration with Entity Framework Code First

前端 未结 2 1309
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-05 01:00

I have a project using the last version of EF CF with PostgreSQL and Npgsql.

My model looks like:

[Table(\"mytable\")]
public class MyTable
{
    [Co         


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-05 01:43

    If I'm not missing something - you'd want some generic way of changing the naming convention for tables?

    The EF6 has the custom conventions feature - it's still not official version, but if it works for you, some links...

    http://entityframework.codeplex.com/wikipage?title=Custom%20Conventions

    In your case, you'd have to implement it for the class/Type I guess - e.g. (some pseudo code)...

    1) implement IConfigurationConvention (you can check the EF source for EntityConventionBase)

    2) In the Apply - change how the Table names are generated via configuration (ToTable()) - to something like .ToLowerCase()

    3) add to conventions...

    For example...

    public class SmallCapsEntitiesConfigurationConvention
        : IConfigurationConvention
    {
        public void Apply(Type memberInfo, Func configuration)
        {
            configuration().ToTable(memberInfo.Name.ToLowerInvariant(), null);
        }
    }
    

    You can see one example here
    http://blog.cincura.net/233167-custom-conventions-in-entity-framework-6-helping-firebird/

    Otherwise, I have no idea about Npgsql / PostgreSQL - it did seem a bit 'raw' to me. But you can handle it on the EF side.

提交回复
热议问题