Book a Demo

Author Topic: How to model C# class and SQL2005 data model in sa  (Read 5354 times)

pocketom

  • EA User
  • **
  • Posts: 97
  • Karma: +0/-0
    • View Profile
How to model C# class and SQL2005 data model in sa
« on: March 17, 2010, 01:26:52 am »
I just tried to model a simple test class. An abstract baseclass inherited by a concrete class. Then I changed the stereotype of the classes from EMPTY to 'table'. I thought now I could define table properties to reflect the class as a tabe on my database. The same I did for all member variables, I assigned the stereotype 'column' for each class attribute.
Then I was able to generate a DDL file as well as C# classes from the same class diagram model! But trouble started when I tried to synchronize my model again with the C# code. It generated member variables from type 'varchar' in my C# class, after changing that to 'string' it generated strings instead of varchars in the DDL...

So I guess it's not the intention to use a model to create both sourcecode and DDL from the same...??? Or is there a way to do so? Would greatly help to keep things consistant and save time!

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: How to model C# class and SQL2005 data model i
« Reply #1 on: March 17, 2010, 02:05:10 am »
I think to achieve what you want you should look at the EA example project and how to use UML transformation from PIM to PSM(s). That's just a hint, never used that myself.

HTH
Günther

Graham_Moir

  • EA User
  • **
  • Posts: 749
  • Karma: +10/-15
    • View Profile
Re: How to model C# class and SQL2005 data model i
« Reply #2 on: March 17, 2010, 08:23:29 pm »
Yes - should be possible as that's the point of the PIM to PSM transformations.  

pocketom

  • EA User
  • **
  • Posts: 97
  • Karma: +0/-0
    • View Profile
Re: How to model C# class and SQL2005 data model i
« Reply #3 on: March 18, 2010, 11:53:43 pm »
Thanx for the hint, I tried it and it works (almost). I created a simple UML class diagram (is that the correct PIM to start?) with 3level inheritance (root class, abstract class, concrete class). Then I used "Transform..." instead of "Code Generation" and selected C# and DDL.

The C# classes look fine, the DLL almost fine. Problem is:

Code: [Select]
CREATE TABLE Login (
      passWord string,
      userName string,
      loginID Integer NOT NULL
)

I'd like to have nvarchar instead of string in my DDL ;-)



Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: How to model C# class and SQL2005 data model i
« Reply #4 on: March 19, 2010, 12:30:30 am »
Nice to hear (read) that, you're welcome  :D !!

Quote
(is that the correct PIM to start?)
Yes exactly, that's what its purposed for and how it works.

I'm pretty sure someone else will help you further, with your DDL code generation problem (I'm not a specialist for that, and just "burned my fingers" with a wrong answer about DDL code generation recently).

Have nice day,
g.

pocketom

  • EA User
  • **
  • Posts: 97
  • Karma: +0/-0
    • View Profile
Re: How to model C# class and SQL2005 data model i
« Reply #5 on: March 19, 2010, 12:54:23 am »
Hey, thanx!

I guess I need to set all PIM classes to Language: <none>

Then there are only 4 native datatypes left: Boolean, String, Integer, UnlimitedNatural

But I miss Date for example...

EDIT: I added Stereotype "Property" to all class attributes, because setting the property checkbox automatically sets this to Java (geXXX, setXXX). What else Stereotypes do I need (e.g. I can't find one for Class itself)?
« Last Edit: March 19, 2010, 12:56:13 am by pocketom »

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: How to model C# class and SQL2005 data model i
« Reply #6 on: March 19, 2010, 01:39:38 am »
Hi,

I think setting language to <none> is very appropriate for the PIM classes.
Date isn't really considerable a 'primitive'  type (and I guess that's what you have at hand there), despite from a logical point of view Date is a kind of primitive value type. Further I know that it's supported in your special PSM environment (C#, SQL-Server, right??), but I wouldn't expect to have it available when designing the PIM.
May be Geert Bellekens knows better than me, as far I've seen he seems to have more experience in this particular things, than me.

HTH
Günther

P.S.: Take a look at you message box please, if you don't know it's pretty decent to see that you've got a PM  ;) ...

pocketom

  • EA User
  • **
  • Posts: 97
  • Karma: +0/-0
    • View Profile
Re: How to model C# class and SQL2005 data model i
« Reply #7 on: March 19, 2010, 09:06:36 pm »
Ok thx! I should contact him these days...

Does anybody know if there is additional documentation on that topic?

I found only these links:

http://www.sparxsystems.com/resources/mda/
http://www.sparxsystems.com/resources/mda/writing_transformations.html
http://www.sparxsystems.com/resources/mda/intermediary_language.html

Especially some help on the intermediary language would be good! I tried already to tune the DDL transformation a bit so that I get nvarchar instead of string in my DDL. I tried it with that:
Code: [Select]
CONVERT TYPE(<destinationLanguage>,<originalType>)  
But I don't know where to set the target Type 'nvarchar' (we always want nvarchar conversion from strings). With that line I only tell which original type I want to transform in my destination Language, but not how to transform right?


Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: How to model C# class and SQL2005 data model i
« Reply #8 on: March 22, 2010, 08:33:03 am »
I've found that I prefer to explicitly put my preferences into the template.  ie.

Code: [Select]
%if attType=="string"%
  type="nvarchar"
%elseIf ...


%endIf%

The CONVERT_TYPE macro is only as useful as the types and common types defined for each of the languages you are using.  This method also allows for special cases such as.

Code: [Select]
%if attTag:"sqlType" != ""%
  type=%qt%attTag:"sqlType"%qt%
%elseIf attType=="string"%
  type="nvarchar"
%elseIf ...


%endIf%

pocketom

  • EA User
  • **
  • Posts: 97
  • Karma: +0/-0
    • View Profile
Re: How to model C# class and SQL2005 data model i
« Reply #9 on: March 22, 2010, 08:47:09 pm »
Thanx! That seems like what I was looking for.