Model first usage.

Aug 30, 2012 at 2:59 PM

Maybe I'm being dense (very possible) but I don't see how to get this to work with Model first.  The step by step instructions on this site show how to use this for code first, and it look pretty good.  But I’m not following how to set this up I my project when I have an EDMX.  Can anyone provide an example, or point me in the correct direction?  Thanks in advance!

Sep 1, 2012 at 8:10 AM

Hi,

Model-first is easy. Just follow the Step-by-step instructions for using M2M with WCR RIA Services&referringTitle, but skip the step where I explained creating MyEFContext.

In general, this is what needs to be done:

  1. Create an EDMX model including M2M relations
  2. Create link table entities as POCO classes (they should not be part of your EDMX model)
  3. Create partial classes for both parties of the M2M association (Product and Order in the documentation)
  4. Create link table views in these partial classes
  5. Configure your domain service to make use of M2M associations.

I hope this answers your question and helps to get you started.

Good luck,

Merijn

Sep 5, 2012 at 7:25 PM
Edited Sep 5, 2012 at 7:36 PM

I appreciated your response, I've followed the steps (except regarding the MyEFContext) and my service project compiles! But the Silverlight client does not.  I get this error:

Error 3 Association named 'Person_PersonTags' defined on entity type 'ExpertAssist.DataObjects.Person' is invalid: OtherKey property named 'Object1_Int64_Id0' cannot be found on entity type 'ExpertAssist.DataObjects.PersonTag'.

The normally generated *.Web.g.cs is not generated so I'm not able to look at the file to see any details.  My keys on both my tables Person and Tag are BigInt (Int64) so that part looks promising, but it looks like it is not generating the property noted in the error message.

Using the sample project Dog/Trainer I changed the type of DogId from int to long and TrainerId from int to long and recieved the same basic error:

Error 1 Association named 'Dog_DogTrainers' defined on entity type 'RIAServices.M2M.Demo.Web.Model.Dog' is invalid: OtherKey property named 'Object1_Int64_Id0' cannot be found on entity type 'RIAServices.M2M.Demo.Web.Model.DogTrainer'. RIAServices.M2M.Demo

Looks like there is something that does not like longs as key types.  Have you seen this issue yet?

Sep 5, 2012 at 7:45 PM

Hi Cevans,

Good top hear that you made progress. Your analysis is right, the generic LinkTable class currently does not support longs as key types. I'll make this a workitem and fix it asap.

Do you have the ability to change your key type to int, just to see if everything else works, or is this too much effort?

Kind regards,

Merijn

Sep 5, 2012 at 7:46 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Sep 5, 2012 at 8:26 PM
Edited Sep 5, 2012 at 8:29 PM

No, the DB is an existing DB.  But I found the place in the code, in the LinkTable.cs, made the appropriate changes (added the properties for Object[1,2,3]_Int64_Id[1,2,3], returns long) and it seems to work now.  I have not done any real testing yet, but the project compiles.

Sep 5, 2012 at 8:31 PM

Thanks for trying it out. I'll let you know when I release a new Nuget package that adds support for long int's.

Sep 5, 2012 at 8:36 PM

Thanks, any idea when that might be?  Hate to push, but this is really needed for my behind schedule project.  Do you have any issue with me just referencing the DLL's directly if not soon?

Sep 6, 2012 at 7:25 AM

It would help if you could share the changes that you made.

Sep 6, 2012 at 4:10 PM
Edited Sep 6, 2012 at 4:55 PM

Sorry about that I made the assumption based on your comment at 1:45 pm yesterday saying ... "the generic LinkTable class currently does not support longs" that you already knew the fix.  My bad, what do that say about the word assume; It makes an ass out of u and me...

So all I did was add 6 properties to the LinkTable.cs:

/* Start Object1 Int63 */
[EditorBrowsable(EditorBrowsableState.Never)]
public long Object1_Int64_Id0
{
    get { return GetKey(x => x.Object1_Int64_Id0); }
    set { SetKey(x => x.Object1_Int64_Id0, value); }
}

[EditorBrowsable(EditorBrowsableState.Never)]
public long Object1_Int64_Id1
{
    get { return GetKey(x => x.Object1_Int64_Id1); }
    set { SetKey(x => x.Object1_Int64_Id1, value); }
}

[EditorBrowsable(EditorBrowsableState.Never)]
public long Object1_Int64_Id2
{
    get { return GetKey(x => x.Object1_Int64_Id2); }
    set { SetKey(x => x.Object1_Int64_Id2, value); }
}
/* End Object1 Int63 */

/* Start Object2 Int63 */
[EditorBrowsable(EditorBrowsableState.Never)]
public long Object2_Int64_Id0
{
    get { return GetKey(x => x.Object2_Int64_Id0); }
    set { SetKey(x => x.Object2_Int64_Id0, value); }
}

[EditorBrowsable(EditorBrowsableState.Never)]
public long Object2_Int64_Id1
{
    get { return GetKey(x => x.Object2_Int64_Id1); }
    set { SetKey(x => x.Object2_Int64_Id1, value); }
}

[EditorBrowsable(EditorBrowsableState.Never)]
public long Object2_Int64_Id2
{
    get { return GetKey(x => x.Object2_Int64_Id2); }
    set { SetKey(x => x.Object2_Int64_Id2, value); }
}
/* End Object2 Int63 */

As stated I did not do full testing, but I have done some light testing just by played with the generated object in my Silverlight project and they are linked etc.

You've done a great job on this project, thank you for all the work you have done, it fills a HUGE hole in RIA, an otherwise great client data access layer.  I wish they had RIA Services for WPF

Sep 6, 2012 at 8:44 PM
Hi Cevans,

Sorry for any confusion. You did exactly the right thing by adding these 6 properties. I knew this, but I asked for your code to make sure that I add the right type of the properties you needed.
Anyway, I made this change to the link table class and just pushed new versions of RIAServices.M2M.LinkTable and RIAServices.M2M to Nuget.org. You should be able to perform an update on these package to get these changes into your project.

Could you let me know if this solves your problem, such that I can close the item on codeplex.
Thanks in advance,

Kind regards,
Merijn



On 6-9-2012 17:10, cevans wrote:

From: cevans

Sorry about that I made the assumption based on your comment at 1:45 pm yesterday saying ... "the generic LinkTable class currently does not support longs" that you already knew the fix. My bad, what do that say about the word assume Make and ass out of u and me...

So all I did was add 6 properties to the LinkTable.cs:

/* Start Object1 Int63 */
[EditorBrowsable(EditorBrowsableState.Never)]
public long Object1_Int64_Id0
{
    get { return GetKey(x => x.Object1_Int64_Id0); }
    set { SetKey(x => x.Object1_Int64_Id0, value); }
}

[EditorBrowsable(EditorBrowsableState.Never)]
public long Object1_Int64_Id1
{
    get { return GetKey(x => x.Object1_Int64_Id1); }
    set { SetKey(x => x.Object1_Int64_Id1, value); }
}

[EditorBrowsable(EditorBrowsableState.Never)]
public long Object1_Int64_Id2
{
    get { return GetKey(x => x.Object1_Int64_Id2); }
    set { SetKey(x => x.Object1_Int64_Id2, value); }
}
/* End Object1 Int63 */

/* Start Object2 Int63 */
[EditorBrowsable(EditorBrowsableState.Never)]
public long Object2_Int64_Id0
{
    get { return GetKey(x => x.Object2_Int64_Id0); }
    set { SetKey(x => x.Object2_Int64_Id0, value); }
}

[EditorBrowsable(EditorBrowsableState.Never)]
public long Object2_Int64_Id1
{
    get { return GetKey(x => x.Object2_Int64_Id1); }
    set { SetKey(x => x.Object2_Int64_Id1, value); }
}

[EditorBrowsable(EditorBrowsableState.Never)]
public long Object2_Int64_Id2
{
    get { return GetKey(x => x.Object2_Int64_Id2); }
    set { SetKey(x => x.Object2_Int64_Id2, value); }
}
/* End Object2 Int63 */

As stated I did not do full testing, but I have done some light testing just by played with the generated object in my Silverlight project and they are linked etc.