我目前在一个解决方案中有以下内容:
- 核心项目(数据访问、商业逻辑、数据访问的 petapoco、管道等)
- 模型项目(仅用于属性的模型和 petapoco 装饰)
- Web 项目(用于演示的 MVC 项目
我想让我的模型和核心分开,但我不能在两个地方都有 PetaPoco.cs。我将如何将它分开并且仍然能够使用 PetaPoco 属性装饰我的模型项目中的 POCO?
我不希望 Models 项目依赖于 Core 项目。
我确实创建了这个单独的类,只在 Models 项目中,所以我可以装饰 POCO,但是 Core PetaPoco 项目没有正确获取这些属性。它过于依赖 PocoData。
建议?
// Poco's marked [Explicit] require all column properties to be marked
[AttributeUsage(AttributeTargets.Class)]
public class ExplicitColumnsAttribute : Attribute
{
}
// For non-explicit pocos, causes a property to be ignored
[AttributeUsage(AttributeTargets.Property)]
public class IgnoreAttribute : Attribute
{
}
// For explicit pocos, marks property as a column and optionally supplies column name
[AttributeUsage(AttributeTargets.Property)]
public class ColumnAttribute : Attribute
{
public ColumnAttribute() { }
public ColumnAttribute(string name) { Name = name; }
public string Name { get; set; }
}
// For explicit pocos, marks property as a result column and optionally supplies column name
[AttributeUsage(AttributeTargets.Property)]
public class ResultColumnAttribute : ColumnAttribute
{
public ResultColumnAttribute() { }
public ResultColumnAttribute(string name) : base(name) { }
}
// Specify the table name of a poco
[AttributeUsage(AttributeTargets.Class)]
public class TableNameAttribute : Attribute
{
public TableNameAttribute(string tableName)
{
Value = tableName;
}
public string Value { get; private set; }
}
// Specific the primary key of a poco class (and optional sequence name for Oracle)
[AttributeUsage(AttributeTargets.Class)]
public class PrimaryKeyAttribute : Attribute
{
public PrimaryKeyAttribute(string primaryKey)
{
Value = primaryKey;
autoIncrement = true;
}
public string Value { get; private set; }
public string sequenceName { get; set; }
public bool autoIncrement { get; set; }
}
[AttributeUsage(AttributeTargets.Property)]
public class AutoJoinAttribute : Attribute
{
public AutoJoinAttribute() { }
}