Im Moment habe ich die folgenden in einer Lösung:Wie würde ich ein separates Model-Projekt mit PetaPoco verwenden?
- Kernprojekt (Datenzugriff, biz Logik, petapoco für den Datenzugriff, die Sanitär-, etc.)
- Modelle Projekt (nur Modelle und Dekorationen petapoco für Attribute nur)
- Webprojekt (MVC-Projekt für die Präsentation
ich möchte, dass meine Modelle und Core seperate haben, aber ich kann nicht PetaPoco.cs in beiden Orten haben. Wie würde ich es trennen und noch in der Lage sein, dekoriere die POCOs in meinen Modellen Projekt mit PetaPoco Attributen?
Ich möchte nicht, dass das Models-Projekt eine Abhängigkeit vom Core-Projekt hat.
Ich habe diese separate Klasse nur im Models-Projekt erstellt, damit ich die POCOs dekorieren kann, aber die Attribute werden vom Core PetaPoco-Projekt nicht richtig aufgenommen. Es verlässt sich zu sehr auf PocoData.
Vorschläge?
// 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() { }
}
PetaPoco ist nur eine Klassendatei, also wäre es wohl zu viel Aufwand in einem eigenen Projekt zu haben. Muss darüber nachdenken, ob es sich lohnt, mein Modellprojekt zu trennen oder nicht. Vielen Dank. – Shane
Ja, ich stimme zu (ich benutze PetaPoco). Gib einfach die Optionen. . . – patmortech
Ich ging voran und tötete gerade mein Models-Projekt und fusionierte zurück in Core. Kein separates Modellprojekt. Pragmatismus gewinnt. Akzeptiere deine Antwort, da ich glaube, du hast bestätigt, dass ich einfach vereinfachen sollte. :) – Shane