13.07.2015 Views

C# in Depth

C# in Depth

C# in Depth

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

LINQ to SQL317■ I changed the type of the Severity, Status, and UserType properties to theirenum equivalents (hav<strong>in</strong>g copied those enumerations <strong>in</strong>to the project).■ I renamed the parent and child properties used for the associations betweenDefect and DefectUser—the designer guessed suitable names for the otherassociations, but had trouble here because there were two associations betweenthe same pair of tables.Figure 12.1 shows the designer diagram after all of these changes.As you can see, the model <strong>in</strong> figure 12.1 is exactly the same as the code modelshown <strong>in</strong> figure 11.3, except without the enumerations. The public <strong>in</strong>terface is so similarthat we can create <strong>in</strong>stances of our entities with the same sample data code. If youlook <strong>in</strong> the <strong>C#</strong> code generated by the designer (DefectModel.designer.cs), you’llf<strong>in</strong>d five partial classes: one for each of the entities, and the DefectModelDataContextclass I mentioned earlier. The fact that they’re partial classes is important when itcomes to mak<strong>in</strong>g the sample data creation code work seamlessly. I had created a constructorfor User, which took the name and user type as parameters. By creat<strong>in</strong>ganother file conta<strong>in</strong><strong>in</strong>g a partial User class, we can add that constructor to our modelaga<strong>in</strong>, as shown <strong>in</strong> list<strong>in</strong>g 12.1.Figure 12.1 The LINQ to SQL classes designershow<strong>in</strong>g the rearranged and modified entitiesLicensed to Rhona Hadida

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!