Quantcast
Channel: EntityFramework Reverse POCO Code First Generator
Viewing all 1642 articles
Browse latest View live

New Post: differences in generated classes

$
0
0
When running the T4 template (Database.tt), some of our team members get classes generated with constructors that set default values for boolean/bit properties/columns, while some get constructors that do not do this. Is there some kind of setting that determines this ? The problem is that when we commit to our source control (Git), those of us with one version of the constructor will be in conflict with those with the other constructor version. Someone on our team tracked this down to line 801 of EF.Reverse.POCO.ttinclude:

<#=col.NameHumanCase #> = <#=col.Default #>;


Any suggestions are appreciated.

Thanks.

New Post: StoredProcedure.CheckNullable()

$
0
0
Does this make sense, so that we don't have to update the NotNullable collection?
            public static string CheckNullable(DataColumn col)
            {
                string result = string.Empty;
                result = (col.AllowDBNull 
                              && Type.GetType(col.DataType.AssemblyQualifiedName, false, true)
                                            .IsValueType)
                             ? "? "
                             : " ";
                return result;
            }

Edited Unassigned: Bug when view contains period character? [163]

$
0
0
Hi there.

I have a view name EGData.Bolig.CreditorOpenInvoices

I have tried using renaming to fix namespace related issues.

TableRename = (name, schema) =>
{
return name.Replace(".Bolig.", "");
};


When querying through ef I get an error in the code (when calling ToTable method) generated by EF Poco Generator:

return (
from invoice in context.EgDataCreditorOpenInvoices
select invoice)
.ToList()

EF Poco code:

internal class EgDataCreditorOpenInvoicesConfiguration : EntityTypeConfiguration<EgDataCreditorOpenInvoices>
{
public EgDataCreditorOpenInvoicesConfiguration()
: this("dbo")
{
}

public EgDataCreditorOpenInvoicesConfiguration(string schema)
{
ToTable(schema + ".EGData.Bolig.CreditorOpenInvoices"); // EXCEPTION HERE
HasKey(x => x.CreditorNumber);

Property(x => x.CreditorNumber).HasColumnName("CreditorNumber").IsRequired().HasColumnType("decimal");
Property(x => x.Company).HasColumnName("Company").IsOptional().HasColumnType("smallint");
Property(x => x.Department).HasColumnName("Department").IsOptional().HasColumnType("smallint");
Property(x => x.DueDate).HasColumnName("DueDate").IsOptional().HasColumnType("datetime");
Property(x => x.Sum).HasColumnName("Sum").IsOptional().HasColumnType("money").HasPrecision(19,4);
Property(x => x.Deposit).HasColumnName("Deposit").IsOptional().HasColumnType("money").HasPrecision(19,4);
Property(x => x.CreditorPaymentId).HasColumnName("CreditorPaymentId").IsOptional().IsUnicode(false).HasColumnType("varchar").HasMaxLength(24);
}
}


An exception of type 'System.ArgumentException' occurred in EntityFramework.dll but was not handled in user code
Additional information: The database name 'dbo.EGData.Bolig.CreditorOpenInvoices' is invalid. Database names must be of the form [<schema_name>.]<object_name>.


Any thoughts are appreciated :-)

Commented Unassigned: Bug when view contains period character? [163]

$
0
0
Hi there.

I have a view name EGData.Bolig.CreditorOpenInvoices

I have tried using renaming to fix namespace related issues.

TableRename = (name, schema) =>
{
return name.Replace(".Bolig.", "");
};


When querying through ef I get an error in the code (when calling ToTable method) generated by EF Poco Generator:

return (
from invoice in context.EgDataCreditorOpenInvoices
select invoice)
.ToList()

EF Poco code:

internal class EgDataCreditorOpenInvoicesConfiguration : EntityTypeConfiguration<EgDataCreditorOpenInvoices>
{
public EgDataCreditorOpenInvoicesConfiguration()
: this("dbo")
{
}

public EgDataCreditorOpenInvoicesConfiguration(string schema)
{
ToTable(schema + ".EGData.Bolig.CreditorOpenInvoices"); // EXCEPTION HERE
HasKey(x => x.CreditorNumber);

Property(x => x.CreditorNumber).HasColumnName("CreditorNumber").IsRequired().HasColumnType("decimal");
Property(x => x.Company).HasColumnName("Company").IsOptional().HasColumnType("smallint");
Property(x => x.Department).HasColumnName("Department").IsOptional().HasColumnType("smallint");
Property(x => x.DueDate).HasColumnName("DueDate").IsOptional().HasColumnType("datetime");
Property(x => x.Sum).HasColumnName("Sum").IsOptional().HasColumnType("money").HasPrecision(19,4);
Property(x => x.Deposit).HasColumnName("Deposit").IsOptional().HasColumnType("money").HasPrecision(19,4);
Property(x => x.CreditorPaymentId).HasColumnName("CreditorPaymentId").IsOptional().IsUnicode(false).HasColumnType("varchar").HasMaxLength(24);
}
}


An exception of type 'System.ArgumentException' occurred in EntityFramework.dll but was not handled in user code
Additional information: The database name 'dbo.EGData.Bolig.CreditorOpenInvoices' is invalid. Database names must be of the form [<schema_name>.]<object_name>.


Any thoughts are appreciated :-)

Comments: Fixed. See this [changeset](https://efreversepoco.codeplex.com/SourceControl/changeset/65a878759633).

New Post: StoredProcedure.CheckNullable()

$
0
0
I've tested it against my test database and it didn't make any difference, i.e. the generated code was the same as before.
Is there a missing entry in the NotNullable collection ?

New Post: How do I stop this table from being pluralized?

$
0
0
Try doing both of these:
new CustomPluralizationEntry("Settings_TAS", "Settings_TAS")

TableRename = (name, schema) =>
{
    return name.Replace("_TAS", "_Tas");
};

New Post: differences in generated classes

$
0
0
Those defaults are picked up from the extended properties in your database.

Here are your extended properties:
SELECT  s.name AS [schema],
        t.name AS [table],
        c.name AS [column],
        value AS [property]
FROM    sys.extended_properties AS ep
        INNER JOIN sys.tables AS t
            ON ep.major_id = t.object_id
        INNER JOIN sys.schemas AS s
            ON s.schema_id = t.schema_id
        INNER JOIN sys.columns AS c
            ON ep.major_id = c.object_id
               AND ep.minor_id = c.column_id
WHERE   class = 1
ORDER BY t.name

New Post: StoredProcedure.CheckNullable()

$
0
0
Yeah object was missing.



Sent via the Samsung GALAXY S®4 Active™, an AT&T 4G LTE smartphone



New Post: Views - LeftJoin - PrimaryKey(s)

$
0
0
Hi Mathias,

EF won't work with any view/table without a primary key.
Because you are joining to the dbo.OrderDetail, the dbo.[Order].Id will be duplicated for every row of order details, and therefore cannot be used as a primary key due to it not being unique. The generator is then forced to use all your columns that are not nullable as primary keys. Hence the primary key being defined as HasKey(x => new { x.OrderId, x.CustomerId, x.ShippingName, x.ShippingAddress, x.ShippingCity, x.ShippingRegion, x.ShippingZip, x.ShippingCountry, x.IsCancelled });

However, you are seeing a problem as even with all these columns selected, your data is creating a duplicate primary key.
Using ROW_NUMBER(), NEWID() or NEWSEQUENTIALID() are all ideal, as this guarantees a unique column per row.

The only problem with using a "select * from..." is that you no longer specify a WHERE clause in the database, and it will be done in LINQ after you have retrieved all the data from the database, which could be huge. This is definitely the wrong solution. Just wait till that view returns a million rows back to your application before your linq query gets its hands on it.

New Post: StoredProcedure.CheckNullable()

Commented Unassigned: Filtering of "Navigation Properties" [157]

$
0
0
When building objects and thinking about DDD and aggregate boundaries, one often might choose to deliberately NOT have a full-on navigation property between aggregates, and only keep the ID of the related entity. It would be good to be able to filter the list of relationships that are generated using some sort of predicate filter.

I spoke with Simon who suggested that I could customise the EF.Reverse.POCO.Core.ttinclude file, searching for:

```
var fkList = reader.ReadForeignKeys(TableRename);
```
and filtering the values.

This is a suitable workaround, although obviously it would be preferable if the core ttinclude file simply referenced a `Func<ForeignKey>` defined somewhere in my .tt files. :)
Comments: I was helping Julie Lerman yesterday with this too. I will definitely make this an option in the tt settings file.

Commented Unassigned: Bug when view contains period character? [163]

$
0
0
Hi there.

I have a view name EGData.Bolig.CreditorOpenInvoices

I have tried using renaming to fix namespace related issues.

TableRename = (name, schema) =>
{
return name.Replace(".Bolig.", "");
};


When querying through ef I get an error in the code (when calling ToTable method) generated by EF Poco Generator:

return (
from invoice in context.EgDataCreditorOpenInvoices
select invoice)
.ToList()

EF Poco code:

internal class EgDataCreditorOpenInvoicesConfiguration : EntityTypeConfiguration<EgDataCreditorOpenInvoices>
{
public EgDataCreditorOpenInvoicesConfiguration()
: this("dbo")
{
}

public EgDataCreditorOpenInvoicesConfiguration(string schema)
{
ToTable(schema + ".EGData.Bolig.CreditorOpenInvoices"); // EXCEPTION HERE
HasKey(x => x.CreditorNumber);

Property(x => x.CreditorNumber).HasColumnName("CreditorNumber").IsRequired().HasColumnType("decimal");
Property(x => x.Company).HasColumnName("Company").IsOptional().HasColumnType("smallint");
Property(x => x.Department).HasColumnName("Department").IsOptional().HasColumnType("smallint");
Property(x => x.DueDate).HasColumnName("DueDate").IsOptional().HasColumnType("datetime");
Property(x => x.Sum).HasColumnName("Sum").IsOptional().HasColumnType("money").HasPrecision(19,4);
Property(x => x.Deposit).HasColumnName("Deposit").IsOptional().HasColumnType("money").HasPrecision(19,4);
Property(x => x.CreditorPaymentId).HasColumnName("CreditorPaymentId").IsOptional().IsUnicode(false).HasColumnType("varchar").HasMaxLength(24);
}
}


An exception of type 'System.ArgumentException' occurred in EntityFramework.dll but was not handled in user code
Additional information: The database name 'dbo.EGData.Bolig.CreditorOpenInvoices' is invalid. Database names must be of the form [<schema_name>.]<object_name>.


Any thoughts are appreciated :-)

Comments: wow that was quick. thanks

New Post: StoredProcedure.CheckNullable()

$
0
0
I'll pull here in a minute and check it out


New Post: differences in generated classes

$
0
0
Would the values in INFORMATION_SCHEMA be the same things that you find in the table designer ? I believe that the person who has different info in his constructors has the same database defaults (e.g. 0 for a bit column) that I do, at least for the one table that we're looking at. I think he's running a different edition of Visual Studio (Community Edition) than I am, but that's the only environmental difference we've been able to pinpoint.

Source code checked in, #65a878759633

$
0
0
Case 163. Handle views and table names with periods.

Source code checked in, #ece0f476f4bf

$
0
0
Changed NotNullable to be List<string> and include object.

New Post: Views - LeftJoin - PrimaryKey(s)

$
0
0
Hi Simon,

thanks for clarifying this.

Best regards Mathias

New Post: differences in generated classes

$
0
0
It will not matter what version of visual studio he has as the generator uses its own SQL it fires at the database, and does not use any visual studio properties apart from being able to scan for a connection string and add/remove files to the project for the generated code.

Try backing up your database, and restoring it on the one that generates different code to double check.
Or alternatively, just turn off defaults altogether by altering the SQL to be
'' AS [Default]

Source code checked in, #dac870974d3d

$
0
0
Include System.Collections.Generic if generating stored procedures.

Source code checked in, #53058ae7c258

$
0
0
Finally sorted out Stored Procedure generation.
Viewing all 1642 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>