Sorry this moment is all over here ... but I feel like a dog chasing my tail, and I'm all embarrassed at this point.
I am trying to see the cleanest way to develop a three-tier solution (IL, BL, DL), where DL uses ORM for abstract access to the database.
Wherever I have seen, people use LinqToSQL or LLBLGen Pro to create objects that represent database tables, and belong to these classes in all three layers. It seems that 40-year-old coding patterns have been ignored - or a paradigm shift has occurred, and I skipped part of the explanation as to why this works great for this.
Nevertheless, it seems that there is still reason to believe that the data storage mechanism is agnostic - look what just happened with LinqToSQL: a lot of code was written with it - only for MS to refuse this ... Therefore, I would like to isolate ORM- part as best as possible, just don't know how to do it.
So, back to the absolute basics, here are the main parts that I want to assemble in a very simple way:
Collections that I start with: UL.dll BL.dll DL.dll
Main classes:
A message class that has a property that displays the collection (called MessageAddresses) of MessageAddress objects:
class Message
{
public MessageAddress From {get;}
public MessageAddresses To {get;}
}
Functions per layer:
BL provides a UI method called GetMessage (Guid id) that returns an instance of Message.
BL, in turn, wraps DL.
DL ProviderFactory, .
DL.ProviderFactory (... ) , GetMessage (Guid id) SaveMessage ( )
, Linq2SQL, LLBLGen Pro , ORM (, VistaDB).
:
.
, , .
, , ORM, DL.
, UL BL.
, , :
a) BL
) Db/Orm/Manual ( "DbMessageRecord", "MessageEntity" - , ORM ), DL.
c) BL DL
d) DL, BL BL, BL BL- (: DbMessageRecord)?
UL:
Main()
{
id = 1;
Message m = BL.GetMessage(id);
Console.Write (string.Format("{0} to {1} recipients...", m.From, m.To.Count));
}
BL:
static class MessageService
{
public static Message GetMessage(id)
{
DbMessageRecord message = DLManager.GetMessage(id);
DbMessageAddressRecord[] messageAddresses = DLManager.GetMessageAddresses(id);
return MapMessage(message,
}
protected static Message MapMessage(DbMessageRecord dbMessage. DbMessageAddressRecord[] dbAddresses)
{
Message m = new Message(dbMessage.From);
foreach(DbMessageAddressRecord dbAddressRecord in dbAddresses){
m.To.Add(new MessageAddress (dbAddressRecord.Name, dbAddressRecord.Address);
}
}
DL:
static class MessageManager
{
public static DbMessageRecord GetMessage(id);
public static DbMessageAddressRecord GetMessageAddresses(id);
}
:
a) , .
b)
c)
d) BL DL DL (, DbMessageRecord), , , ORM, ,... ... ORM BL.
e) ... BL DL , BL DL.
, ... . .