I watched an intro video on DD, and was impressed with the way that it picked up on a FK in a table, and showed the foreign table's values instead of the ID. I tried this myself with a simple example, and I got IDs displayed.
How does it decide what is a FK and what isn't? For example, I tried a very simple database for tracking user actions. A user can assign an action to another user (or him/herself), and gives start and end dates for the action. Here is the SQL...
create table ActionTypes (
ActionTypeID int not null identity(1,1) primary key,
Description varchar(500) not null default ''
)
go
create table Users (
UserID int not null identity(1,1) primary key,
Title varchar(50) not null default '',
FirstName varchar(50) not null default '',
Surname varchar(50) not null default ''
)
go
create table Actions (
ActionID int not null identity(1,1) primary key,
ScheduledStartTime datetime not null default '1 Jan 1900',
ScheduledEndTime datetime not null default '1 Jan 1900',
ActionTypeID int not null foreign key references ActionTypes(ActionTypeID),
ActionedByUserID int not null foreign key references Users(UserID),
AssignedToUserID int not null foreign key references Users(UserID)
)
go
I created an entity framework model from this, then put a RIA service on top of that. I used the RIA service as the context for the DD stuff.
When I ran this, and looked at the Actions table (having added some dummy data directly from SQL management for speed), it did a few things that surprised me...
1) it showed the ActionID column, which is the PK for this table. I thought it was supposed to hide PK fields?
2) The ActionTypeID, ActionedByUserID and AssignedToUserID fields were all shown as numbers, ie the ID value itself. I thought the idea was that DD picked up on FK fields and showed the value from the other table, not the ID value from this table?
3) I couldn't work out how it was supposed to know what value to use from the other table. In the video I saw, it somehow picked up on the right one without anything being done to tell it. In my case, it didn't pick it up, even when one of the tables (ActionTypes)
only had one other field.
Anyone able to explain what's going on to me? I'm finding the lack of decent docs very frustrating!
Thanks
If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/
Just to add to this, I noticed that if I edit the Actions table, it shows the Action type as a dropdown with the description correctly, but if I look at the same record in details view, it just shows the ID. In both cases, it shows the ID as well.
Anyone any ideas? Thanks
If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/
1) it showed the ActionID column, which is the PK for this table. I thought it was supposed to hide PK fields?
I believe this is the way the Domain Service works [:(]
MrYossu
2) The ActionTypeID, ActionedByUserID and AssignedToUserID fields were all shown as numbers, ie the ID value itself. I thought the idea was that DD picked up on FK fields and showed the value from the other table, not the ID value from this table?
My Experience is the this is true in List and Details pages but not in the Edit page and even adding an override of ToString make no differance (Bug?)
MrYossu
3) I couldn't work out how it was supposed to know what value to use from the other table. In the video I saw, it somehow picked up on the right one without anything being done to tell it. In my case, it didn't pick it up, even when one of the tables (ActionTypes)
only had one other field.
To see how it is supposed to wotk try a stright Dynamic Data Entites Framework Project. [:(]
DomainDataSourceDynamic Data 4WCF RIA Services
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
What does your DomainService class look like? For the FK's special handling to happen, you need to make sure that the table the FK goes to also has a Get method in the DomainService.
Another thing to try to help investigation is to do something similar, but using a standard DB like northwind. This way, we can isolate whether the issue relates to your model or to something else.
I tried an experiment, and I think I've found a bug in DD (or a "design feature") when using a domain service
I used the [url=http://chinookdatabase.codeplex.com/]open-source Chinook database[/url] and created two parallel projects, one for entities, and one for a domain service. They both have an entity model, but the latter project has a service on top of the
entity model.
In both cases, I merely added the data source to the project, uncommented the line in Global.asax, added the content name and set scaffolding to true. Oh, actually for the domain service version I had to add an OrderBy() to each of the get methods. I then
ran the projects.
The version built on the entity model displayed just fine. I didn't see a single ID anywhere. Turning to the domain services version, I saw IDs everywhere, including the table's own ID, as well as the foreign key reference ID.
So, it looks like DD doesn't work with domain services out of the box. Whether there's some fix for it or not I don't know, but right now, it seems to fail with domain services.
As to your questions David, I included four related tables in the model, Albums, Artists, Genres and Tracks, and used the default code that was generated, except I needed to add an OrderBy to the getters to avoid a compilation error.
For example, the getter for the Albums table looks like this...
public IQueryable<Album> GetAlbums() {
return this.ObjectContext.Albums.OrderBy(a => a.Title);
}
Is that what you meant? If not, please explain further.
Maybe you could try and duplicate what I did. For the entities version, I just added an entity data model and chose the four albums mentioned above, enabling editing for all four. For the domain service version, I did the same, but added a domain service
which used that model, then added the OrderBy to each of the four getters.
Please try it and let me know if you see the same difference. Maybe you can see what's going on and work out how to get DD to work with domain services.
Thanks again to both of you.
If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/
Just to add on to this, I just tried my own database with an entity model, and it worked fine, so it's obviously some incompatibility with domain services.
The question is, is there a fix for this, or is it a bug that breaks the whole system?
If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/
I have had the same problem with WCF RIA Service template. I don't exactly know why the PK of my tables appears exposed to be filled by the end user even tough it is defined as a "identity". I have worked modifying my MetaData class as to scaffold false
such columns.
Previously, without RIA it worked just fine.
I also have found that what it was "partial" classes before in your MetaData files now they appear as "internal sealed" and they are also automatically generated.
In Mr. Scott Hunter's videos for customizing you Dynamic Data applications it was taught that you can use modifiers there as UIHint, Range and so forth. If you do that now, "overwriting" this class makes you feel like "what was the purpose of creating such
class at all?" It also happnes that if you modify your model you'll have to keep track of any changes made as to reproduce them later in the newly generated files.
In answer to the last couple of comments you made, you shouldn't be modifying the generated files because, as you've seen, your changes will be overwritten if/when you regenerate the model.
The way to do this is to add a partial class definition. As this is in your own file, it won't be overwritten. The internal sealed bits you've seen are on the autogenerated meta classes. You don't need to touch those. Add a new class file, and make it a
partial class of the main entity (Customer, Order, etc). Decorate it with a MetadataType attribute to tell it what class to use for metadata, then add that as a class and decorate individual properties there. All of this is done in your own files.
Hope this helps.
If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/
Hi MrYossu have you tried Northwind? (you can get it from
here) This is a known working DB if you are still having issues here then we may have an issue.
DomainDataSourceDynamic Data 4WCF RIA Services
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
MrYossu
Member
134 Points
144 Posts
How does DD decide what is a FK and what isn't?
Aug 22, 2010 05:57 PM|LINK
Hello,
I watched an intro video on DD, and was impressed with the way that it picked up on a FK in a table, and showed the foreign table's values instead of the ID. I tried this myself with a simple example, and I got IDs displayed.
How does it decide what is a FK and what isn't? For example, I tried a very simple database for tracking user actions. A user can assign an action to another user (or him/herself), and gives start and end dates for the action. Here is the SQL...
I created an entity framework model from this, then put a RIA service on top of that. I used the RIA service as the context for the DD stuff.
When I ran this, and looked at the Actions table (having added some dummy data directly from SQL management for speed), it did a few things that surprised me...
1) it showed the ActionID column, which is the PK for this table. I thought it was supposed to hide PK fields?
2) The ActionTypeID, ActionedByUserID and AssignedToUserID fields were all shown as numbers, ie the ID value itself. I thought the idea was that DD picked up on FK fields and showed the value from the other table, not the ID value from this table?
3) I couldn't work out how it was supposed to know what value to use from the other table. In the video I saw, it somehow picked up on the right one without anything being done to tell it. In my case, it didn't pick it up, even when one of the tables (ActionTypes) only had one other field.
Anyone able to explain what's going on to me? I'm finding the lack of decent docs very frustrating!
Thanks
MrYossu
Member
134 Points
144 Posts
Re: How does DD decide what is a FK and what isn't?
Aug 22, 2010 07:58 PM|LINK
Just to add to this, I noticed that if I edit the Actions table, it shows the Action type as a dropdown with the description correctly, but if I look at the same record in details view, it just shows the ID. In both cases, it shows the ID as well.
Anyone any ideas? Thanks
sjnaughton
All-Star
27320 Points
5459 Posts
MVP
Re: How does DD decide what is a FK and what isn't?
Aug 25, 2010 08:38 PM|LINK
I believe this is the way the Domain Service works [:(]
My Experience is the this is true in List and Details pages but not in the Edit page and even adding an override of ToString make no differance (Bug?)
To see how it is supposed to wotk try a stright Dynamic Data Entites Framework Project. [:(]
DomainDataSource Dynamic Data 4 WCF RIA Services
Always seeking an elegant solution.
davidebb
Contributor
7006 Points
1366 Posts
Microsoft
Re: How does DD decide what is a FK and what isn't?
Aug 25, 2010 09:04 PM|LINK
What does your DomainService class look like? For the FK's special handling to happen, you need to make sure that the table the FK goes to also has a Get method in the DomainService.
thanks,
David
davidebb
Contributor
7006 Points
1366 Posts
Microsoft
Re: How does DD decide what is a FK and what isn't?
Aug 25, 2010 09:28 PM|LINK
Another thing to try to help investigation is to do something similar, but using a standard DB like northwind. This way, we can isolate whether the issue relates to your model or to something else.
David
MrYossu
Member
134 Points
144 Posts
Re: How does DD decide what is a FK and what isn't?
Aug 26, 2010 02:38 PM|LINK
Steve and David,
Thanks for your replies.
I tried an experiment, and I think I've found a bug in DD (or a "design feature") when using a domain service
I used the [url=http://chinookdatabase.codeplex.com/]open-source Chinook database[/url] and created two parallel projects, one for entities, and one for a domain service. They both have an entity model, but the latter project has a service on top of the entity model.
In both cases, I merely added the data source to the project, uncommented the line in Global.asax, added the content name and set scaffolding to true. Oh, actually for the domain service version I had to add an OrderBy() to each of the get methods. I then ran the projects.
The version built on the entity model displayed just fine. I didn't see a single ID anywhere. Turning to the domain services version, I saw IDs everywhere, including the table's own ID, as well as the foreign key reference ID.
So, it looks like DD doesn't work with domain services out of the box. Whether there's some fix for it or not I don't know, but right now, it seems to fail with domain services.
As to your questions David, I included four related tables in the model, Albums, Artists, Genres and Tracks, and used the default code that was generated, except I needed to add an OrderBy to the getters to avoid a compilation error.
For example, the getter for the Albums table looks like this...
public IQueryable<Album> GetAlbums() {
return this.ObjectContext.Albums.OrderBy(a => a.Title);
}
Is that what you meant? If not, please explain further.
Maybe you could try and duplicate what I did. For the entities version, I just added an entity data model and chose the four albums mentioned above, enabling editing for all four. For the domain service version, I did the same, but added a domain service which used that model, then added the OrderBy to each of the four getters.
Please try it and let me know if you see the same difference. Maybe you can see what's going on and work out how to get DD to work with domain services.
Thanks again to both of you.
MrYossu
Member
134 Points
144 Posts
Re: How does DD decide what is a FK and what isn't?
Aug 26, 2010 03:20 PM|LINK
Just to add on to this, I just tried my own database with an entity model, and it worked fine, so it's obviously some incompatibility with domain services.
The question is, is there a fix for this, or is it a bug that breaks the whole system?
klca
Member
507 Points
413 Posts
Question
Aug 26, 2010 04:41 PM|LINK
Hola,
I have had the same problem with WCF RIA Service template. I don't exactly know why the PK of my tables appears exposed to be filled by the end user even tough it is defined as a "identity". I have worked modifying my MetaData class as to scaffold false such columns.
Previously, without RIA it worked just fine.
I also have found that what it was "partial" classes before in your MetaData files now they appear as "internal sealed" and they are also automatically generated.
In Mr. Scott Hunter's videos for customizing you Dynamic Data applications it was taught that you can use modifiers there as UIHint, Range and so forth. If you do that now, "overwriting" this class makes you feel like "what was the purpose of creating such class at all?" It also happnes that if you modify your model you'll have to keep track of any changes made as to reproduce them later in the newly generated files.
Regards
Carlos Porras (El Salvador)
MrYossu
Member
134 Points
144 Posts
Re: Question
Aug 26, 2010 05:48 PM|LINK
Hi Carlos,
In answer to the last couple of comments you made, you shouldn't be modifying the generated files because, as you've seen, your changes will be overwritten if/when you regenerate the model.
The way to do this is to add a partial class definition. As this is in your own file, it won't be overwritten. The internal sealed bits you've seen are on the autogenerated meta classes. You don't need to touch those. Add a new class file, and make it a partial class of the main entity (Customer, Order, etc). Decorate it with a MetadataType attribute to tell it what class to use for metadata, then add that as a class and decorate individual properties there. All of this is done in your own files.
Hope this helps.
sjnaughton
All-Star
27320 Points
5459 Posts
MVP
Re: How does DD decide what is a FK and what isn't?
Aug 26, 2010 07:39 PM|LINK
Hi MrYossu have you tried Northwind? (you can get it from here) This is a known working DB if you are still having issues here then we may have an issue.
DomainDataSource Dynamic Data 4 WCF RIA Services
Always seeking an elegant solution.