CRUD auto generated procedures incorrect syntax

Jan 12, 2016 at 5: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;}

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 
-- 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;


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

Please could you help me with this?


Jan 12, 2016 at 5:39 PM
will look at it asap and let you know
Jan 12, 2016 at 7: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:
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 6: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; }
Jan 13, 2016 at 6: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 8:22 AM
Yes, it works.

Thank you