CRUD auto generated procedures incorrect syntax

Jan 12, 2016 at 4:01 PM
I am trying to create a table, which refers to another one, which primary key is composite key. Something like this:

[Entity(TableName="PrescreeningPeakReferences"), PrimaryKey("SpectrumPeak")]
public interface IPrescreeningPeakReference{
 ISpectrumPeak SpectrumPeak{get; set;}
}

Referenced "ISpectrumPeak" entity:

[Entity(TableName="SpectrumPeaks"), PrimaryKey("Spectrum,OrderId")]
public interface ISpectrumPeak{
  [EntityRef(KeyColumns="SpectrumId"), CascadeDelete,ClusteredIndex]
 ISpectrum Spectrum{get; set;}

[Column("OrderId")]
int OrderId{get;set;}
.....
.....
another properties
}

And by the updating schema I receive an exception. Generated procedure has incorrect syntax. It looks like this:

CREATE PROCEDURE "dbo"."PrescreeningPeakReference_SelectBySpectrumId OrderId"
@SpectrumId int,
@ OrderId int 
AS
BEGIN
SET NOCOUNT ON;
-- Description: Selects entity(ies) by key.
-- VITA/Generated: CRUD/"dbo"."PrescreeningPeakReferences"/SelectByKey/SpectrumId, OrderId
SELECT " OrderId", "SpectrumId"
FROM "dbo"."PrescreeningPeakReferences"
WHERE "SpectrumId" = @SpectrumId AND " OrderId" = @ OrderId;

END

Procedure name contains space as well as parameter "@ OrderId".

Please could you help me with this?

Regards

Milos
Coordinator
Jan 12, 2016 at 4:39 PM
will look at it asap and let you know
Coordinator
Jan 12, 2016 at 6:13 PM
what version are you using?! first, cannot repro it, copied your stuff in a separate test, everything works. One thing I see is that proc name is:
PrescreeningPeakReference_SelectBySpectrumPeakSpectrumIdSpectrumPeakOrderId
notice key columns are SpectrumPeakSpectrumId, SpectrumPeakOrderId
that's because columns in PrescreeningPeakReference are SpectrumPeak_SpectrumId, SpectrumPeak_OrderId
Do you also have EntityRef attribute on SpectrumPeak prop of IPrescreeningPeakReference, that explicitly sets FK column names?
Jan 13, 2016 at 5:16 AM
Sorry I forget. I use latest version of VITA framework and target server is Sql Server 2014.
Yes, I have EntityRef attribute also on SpectrumPeak.

I used the "db first" approach. Database that was previously generated by the "Entity Framework", I converted using the "vdbtool" to VITA and I made the necessary changes. I kept all the "EntityRef" and I added them to the new entities where necessary or for consistency.

Here is entity:
[Entity(TableName = "PrescreeningPeakReferences"),PrimaryKey("SpectrumPeak")]
public interface IPrescreeningPeakReference
{
    [EntityRef(KeyColumns = "SpectrumId, OrderId"), CascadeDelete, ClusteredIndex]
    ISpectrumPeak SpectrumPeak { get; set; }
}
Coordinator
Jan 13, 2016 at 5:23 AM
then here's your answer - remove this space before OrderId in KeyColumns attribute. I will fix this in Vita, to add trimming of spaces
Jan 13, 2016 at 7:22 AM
Yes, it works.

Thank you