关于代码生成器生成的两种格式

Dec 4, 2009 at 4:29 PM

public class Liuyan : IDbObject
 public long Id;
 [AllowNull] [Length(500)] public string LiuyanContent;
 [AllowNull] [Length(50)] public string FromUsername;
 [AllowNull] [Length(50)] public string ToUsername;
 public DateTime? AddDate;
 [AllowNull] [Length(500)] public string Reply;

 public Liuyan Initialize(long Id, string LiuyanContent, string FromUsername, string ToUsername, DateTime? AddDate, string Reply){
  this.Id = Id;
  this.LiuyanContent = LiuyanContent;
  this.FromUsername = FromUsername;
  this.ToUsername = ToUsername;
  this.AddDate = AddDate;
  this.Reply = Reply;
  return this;
 }
}

public abstract class Yanjiu : LinqObjectModel<Yanjiu>
{
 public abstract long? Xuhao { get; set; }
 public abstract long BanjiStudentID { get; set; }
 [AllowNull] [Length(100)] public abstract string KetiName { get; set; }
 [AllowNull] [Length(100)] public abstract string KetiChengyuan { get; set; }
 [AllowNull] [Length(100)] public abstract string Renwu { get; set; }
 [AllowNull] [Length(50)] public abstract string ChenguoType { get; set; }
 public abstract DateTime? OverDate { get; set; }
 [AllowNull] [Length(500)] public abstract string Pingjia { get; set; }
 [AllowNull] [Length(100)] public abstract string Beizhu { get; set; }
 public abstract int? Xuenian { get; set; }
 public abstract int? Xueqi { get; set; }
 [AllowNull] [Length(50)] public abstract string InputUsername { get; set; }
 [AllowNull] [Length(10)] public abstract string InputUserID { get; set; }
 public abstract DateTime? InputDate { get; set; }
 public abstract double? Xuefen { get; set; }
 [AllowNull] [Length(50)] public abstract string Shenhe { get; set; }

 public abstract Yanjiu Initialize(long? Xuhao, long BanjiStudentID, string KetiName, string KetiChengyuan, string Renwu, string ChenguoType, DateTime? OverDate, string Pingjia, string Beizhu, int? Xuenian, int? Xueqi, string InputUsername, string InputUserID, DateTime? InputDate, double? Xuefen, string Shenhe);
}

这两种格式是按什么来判断的,我想都生成第二种格式的,应该怎么做?

 

Coordinator
Dec 5, 2009 at 2:50 AM

要生成第二种的,必须有一个自增主键,类型为long,且名字为Id。

Oracle不支持自增主键,现在代码生成也没有检测序列发生器,所以目前如果从Oracle生成,则都是第一种的。

 

Dec 5, 2009 at 4:24 AM

OK,第一个是因为没设主键,,,谢谢

Dec 5, 2009 at 6:21 AM

<%--  CodeSmith模板:http://www.cnblogs.com/shiningrise/archive/2009/12/05/1617529.html
Name: DbEntry.Net3.6
Author: shiningrise@gmail.com
Description: Create DbEntry.Net3.6 Model from a database table
--%>
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Description="Create a list of properties from database table." %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table that the object is based on." %>
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lephone.Data.Definition;
using Lephone.Linq;

namespace Wz16.Models   //Chang it to you namespace string
{
    /// <summary>
    /// <%= this.SourceTable.Description %>
    /// </summary>
    [DbTable("<%= this.SourceTable.Name %>")]
    public abstract class <%= StringUtil.ToPascalCase(this.SourceTable.Name) %> : LinqObjectModel< <%= StringUtil.ToPascalCase(this.SourceTable.Name) %>>
    {
<% foreach (ColumnSchema column in this.SourceTable.Columns) {  %>
 <% if( StringUtil.ToPascalCase(column.Name) != "Id" ) {%>
  /// <summary>
  /// <%= column.Description %>
        /// </summary>
  <%if( CSharpAlias[column.SystemType.FullName] == "string" )  {%>
  [Length(<%= column.Size %>)] <% if( column.AllowDBNull ) { %>[AllowNull] <% } %>public abstract <%= CSharpAlias[column.SystemType.FullName] %> <%= StringUtil.ToPascalCase(column.Name) %> { get; set; }
  
  <% } else { %>
  public abstract <%= CSharpAlias[column.SystemType.FullName] %> <% if( column.AllowDBNull ) { %>? <% } %><%= StringUtil.ToPascalCase(column.Name) %> { get; set; } 
  <% } %>
  
 <% } %>
<% } %>
 }
}

Dec 5, 2009 at 6:22 AM

生成结果示例:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lephone.Data.Definition;
using Lephone.Linq;

namespace Wz16.Models   //Chang it to you namespace string
{
    /// <summary>
    ///
    /// </summary>
    [DbTable("Liuyan")]
    public abstract class Liuyan : LinqObjectModel< Liuyan>
    {
  /// <summary>
  /// 留言内容
        /// </summary>
  [Length(500)] [AllowNull] public abstract string LiuyanContent { get; set; }
  
  
  /// <summary>
  /// 留言者
        /// </summary>
  [Length(50)] [AllowNull] public abstract string FromUsername { get; set; }
  
  
  /// <summary>
  /// 留言查看对象
        /// </summary>
  [Length(50)] [AllowNull] public abstract string ToUsername { get; set; }
  
  
  /// <summary>
  /// 添加时间
        /// </summary>
  public abstract System.DateTime ? AddDate { get; set; } 
  
  /// <summary>
  /// 回复
        /// </summary>
  [Length(500)] [AllowNull] public abstract string Reply { get; set; }
  
  
 }
}

Coordinator
Dec 5, 2009 at 1:08 PM

恩,不错,在首页上加了个链接,谢谢。

 

Dec 7, 2009 at 7:08 AM

 

<%--

DbEntry.Net3.6 DbEntryDataSource from a database table CodeSimth 模板
Name: DbEntry.Net3.6
Author: shiningrise@gmail.com
Description: Create DbEntry.Net3.6 Model from a database table
--%>
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Description="Create a list of properties from database table." %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table that the object is based on." %>
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>

////////////////////////////////////////////////////////////////////////////
//
// 版本:$Rev: 72 $  
// 作者:$Author: wxy $
// 时间:$Date: 2009-11-16 10:25:05 +0800 (Mon, 16 Nov 2009) $
// 作者网站: http://shiningrise.cnblogs.com
//  说明: 表<%= this.SourceTable.Name %> ( <%= this.SourceTable.Description %> )
//
////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lephone.Web;
using Wz16.Models;
namespace Wz16.Web
{
 /// <summary>
    /// <%= this.SourceTable.Description %>
    /// </summary>
    public class <%= StringUtil.ToPascalCase(this.SourceTable.Name) %>DataSource : DbEntryDataSource< <%= StringUtil.ToPascalCase(this.SourceTable.Name) %> >
    {

    }
}