Friday, March 12, 2010

.Net 3.5 and Partial Classes and Multi Layered System

.Net 3.5 and Partial Classes and Multi Layered System

I want to break my project down into 3 layers of code.

Mainly

Shortcut
 I was hoping to be able to simply create partial classes in the Logic library so I would not have create a brand new set of classes
 Unfortunately you can not create partial classes outside the main library which contains your DBML

Solution
 I can create a class with the same name under the Test1.Logic namespace, and simply inherit the Test1.Data class.

This gives me all the classes and their methods in the Logic library without a lot of code and now I can build my entire logic in the LOGIC library

Hope this gives you a jump start on your project.

I would use this script to quickly create the LOGIC classes from your DATA classes

DECLARE @TableName VARCHAR(500)

DECLARE tc CURSOR FOR

      SELECT      Table_Name

      FROM  Information_Schema.Tables

      WHERE Table_Type = 'BASE TABLE'

      ORDER BY Table_Name

 

OPEN tc

 

FETCH NEXT FROM tc INTO @TableName

WHILE @@FETCH_STATUS = 0

BEGIN

      PRINT 'class ' + @TableName + ' : Test1.Data.' + @TableName + '

      {

      } '

 

      FETCH NEXT FROM tc INTO @TableName

END

 

CLOSE tc

DEALLOCATE tc    

 

Remember though that you will still need to create the datacontext manually

Have an excellent day.


Comments:

Post a Comment

Subscribe to Post Comments [Atom]





<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]