开发者

Change relationship multiplicity in Lightswitch for imported tables

I have two tables in SQL server one Messages and a second Message Bodies. There is a FK relationship between the two (Primary key on Messages to a column (Message ID) on Message Bodies.

Message Bodies has a unique index specified on Message ID to ensure no dupli开发者_如何学Pythoncates.

The goal of all that database work is to ensure a one-or-zero to one mapping.

          +-------------------------+           +------------------------------+
          |  Messages               |           | Message Bodies               |
          |-------------------------|           |------------------------------|
          | PK                      |+----+     | PK                           |
          | Message Header          |     +----+| Message ID                   |
          |                         |           | Message Body                 |
          +-------------------------+           +------------------------------+

When I add this as a data source into Lightswitch it adds a One to Many relationship between these.

How do I change this as the multiplicty settings are disabled?


If you model your SQL data this way, LightSwitch will recognize the 1 to 0..1 relationship:

CREATE TABLE [Messages]
(
    PK int IDENTITY(1,1) not null,
    MessageHeader varchar (50) not null,
    PRIMARY KEY (PK)
)
GO

CREATE TABLE [MessageBodiesWithPK]
( 
    PK int not null,
    MessageBody varchar(50) null,
    PRIMARY KEY (PK),
    FOREIGN KEY (PK) REFERENCES [Messages] (PK)
)
GO

If you can't change your schema, you'll have to hand edit the LSML file. This is not supported, but I've used this fix in the past to correct areas where the data designer doesn't guess my intentions correctly, specifically to fix the implied key on SQL views. You should be looking for the Multiplicity attribute for the AssociationEnd element - set it from "Many" to "One".

To be clear: I would consider hand editing the LSML a last resort. Be sure to check your work in before you do this, because the entire app might be corrupted if you make a mistake (did I mention LSML is undocumented?). Anyway, if you want to give it a shot, look in the Data directory of your project.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜