Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Getting StartedGetting Startedtemplate to create classtemplate to create class
Previous
 
Next
New Post
5/25/2013 11:59 AM
 
I am using DAL 2 and I have to more than 10 tables. is there any way to generate to create classes for these tables.
 
New Post
5/28/2013 10:20 PM
 
If you are looking for something like the EF or LINQ to SQL entity designer that basically allows you to drag and drop a table onto a design surface and create the data class automagically, I'm afraid you are out of luck.

However, the implementation of DAL2 is fairly lightweight.

You don't have to do an enormous amount of hand-coding to create the data model. Most of that is done behind the scenes for you.

You will have to create a class that specifies each table you want to map, and each column and its data type, plus the primary key of the table. But you don't have to create a bunch of CRUD code for each entity.

If it was more than 10 tables, or tables with a very large number of columns, then it might be worthwhile coming up with a script (even a SQL script!) that can generate the bulk of the code for you. Perhaps someone has already done that, but I haven't seen it yet.

I don't think it would be hard to do, and it would be reusable, so if you are planning on doing a lot of this stuff, it could come in handy!

Here is a T-SQL script I just threw together that will write 80% of the item generation code for you. Just nominate the table name at the relevant point, and run it in SQL Management Studio, then copy and paste the results into Visual Studio. It only deals with int, varchar and datetime columns, but is easy to extend for other types.

No warranty supplied!

Declare @TableName as varchar(100)

Set @TableName = 'YOURTABLENAMEHERE'

select '[TableName("' + @TableName + '")]' as SQLLine
union all
select '[PrimaryKey("PutYourPKColumnNameHere")]' as SQLLine
union all
select '[Cacheable("' + @TableName + 's", CacheItemPriority.Default, 20)]' as SQLLine
union all
select '[Scope("ModuleId/PortalId/UserId")]' as SQLLine
union all
select 'public class ' + @TableName
union all
select '{'
union all
select 'public ' +
case Data_Type
when 'varchar' then 'string'
when 'int' then 'int'
when 'datetime' then 'DateTime'
else DATA_TYPE
end
+ ' ' + Column_Name + ' { get; set; }' from information_schema.columns where table_name = @TableName
union all
select '}'
 
New Post
5/28/2013 10:24 PM
 
If you are looking for something like the EF or LINQ to SQL entity designer that basically allows you to drag and drop a table onto a design surface and create the data class automagically, I'm afraid you are out of luck.

However, the implementation of DAL2 is fairly lightweight.

You don't have to do an enormous amount of hand-coding to create the data model. Most of that is done behind the scenes for you.

You will have to create a class that specifies each table you want to map, and each column and its data type, plus the primary key of the table. But you don't have to create a bunch of CRUD code for each entity.

If it was more than 10 tables, or tables with a very large number of columns, then it might be worthwhile coming up with a script (even a SQL script!) that can generate the bulk of the code for you. Perhaps someone has already done that, but I haven't seen it yet.

I don't think it would be hard to do, and it would be reusable, so if you are planning on doing a lot of this stuff, it could come in handy!

Here is a T-SQL script I just threw together that will write 80% of the item generation code for you. Just nominate the table name at the relevant point, and run it in SQL Management Studio, then copy and paste the results into Visual Studio. It only deals with int, varchar and datetime columns, but is easy to extend for other types.

No warranty supplied!

Declare @TableName as varchar(100)

Set @TableName = 'YOURTABLENAMEHERE'

select '[TableName("' + @TableName + '")]' as SQLLine
union all
select '[PrimaryKey("PutYourPKColumnNameHere")]' as SQLLine
union all
select '[Cacheable("' + @TableName + 's", CacheItemPriority.Default, 20)]' as SQLLine
union all
select '[Scope("ModuleId/PortalId/UserId")]' as SQLLine
union all
select 'public class ' + @TableName
union all
select '{'
union all
select 'public ' + 
case Data_Type
when 'varchar' then 'string'
when 'int' then 'int'
when 'datetime' then 'DateTime'
else DATA_TYPE
end 
+ ' ' + Column_Name + ' { get; set; }' from information_schema.columns where table_name = @TableName
union all
select '}'

 
Previous
 
Next
HomeHomeDevelopment and...Development and...Getting StartedGetting Startedtemplate to create classtemplate to create class


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out