Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
R

RubensFarias

@RubensFarias
About
Posts
6
Topics
2
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • What will you call this???
    R RubensFarias

    Actually, "that" removes the 'seconds [and milliseconds]' part from entered datetime, so "2008-11-10 08:00:30.123" => "2008-11-10 08:00:00". Ugly, I agree.

    The Weird and The Wonderful question workspace

  • Generic data fetch with IDataReader
    R RubensFarias

    Hi Mehroz, I'm working on some model limitations and, when I ready to go, I'll post @ CP, for sure. Thanks for your incentive, Rubens

    Database business sales regex question discussion

  • Generic data fetch with IDataReader [modified]
    R RubensFarias

    Looking at System.Data.OleDb implementation through Reflector, GetInt32 and GetValue returns values based on column types, so I think both have similar performance. And, if I had to code an IF inside that generic method, I prefer to stick with current ADO.NET implementation About your second thought, I share your feelings. My main point is to define a simple pattern for data fetch, probably in a structure like Entity (get/set/read) >> Data (DAL/.executeXXX) >> Business (work with loaded data) >> and so on. Thank you for your comments, I really appreciate them. Rubens

    C# business sales regex question discussion

  • Generic data fetch with IDataReader [modified]
    R RubensFarias

    Sorry Michal, here you go. ty

    C# business sales regex question discussion

  • Generic data fetch with IDataReader
    R RubensFarias

    Hi there, I'm looking for some advise for a generic data fetch pattern for IDataReader I'm working on, as follow: // main load using(GenericDataReader reader = new GenericDataReader(cm.ExecuteReader())) { while (reader.Read()) { orders.Add(reader.Get<Order>()); // "GetList" pattern //return new Order(reader); // "Get" pattern } } // generic reader; interface implementation removed public class GenericDataReader : IDataReader { // ... \\ public T Get<T>(string name) { int i = _dataReader.GetOrdinal(name); if (_dataReader.IsDBNull(i)) return default(T); else return (T)_dataReader.GetValue(i); } public T Get<T>() where T : ILoadable, new() { T entity = new T(); entity.Load(this, false); return entity; } } // All business objects must implements this interface public interface ILoadable { void Load(GenericDataReader reader, bool deep); } // Sample business object class Order : ILoadable { int id; Customer customer; // Note DateTime orderDate; DateTime requiredDate; DateTime? shippedDate; List<OrderDetail> orderDetails; public Order(){ } public Order(GenericDataReader reader) { Load(reader, true); } #region ILoadable Members public void Load(GenericDataReader reader, bool deep) { id = reader.Get<int>("OrderID"); customer = reader.Get<Customer>(); // Note orderDate = reader.Get<DateTime>("OrderDate"); requiredDate = reader.Get<DateTime>("OrderRequiredDate"); shippedDate = reader.Get<DateTime?>("OrderShippedDate"); if (deep && reader.NextResult()) { orderDetails = new List<OrderDetail>(); while (reader.Read()) { orderDetails.Add(reader.Get<OrderDetail>()); } } } #endregion } What do you think? Are there any major drawback with this model I'm missing? Are there any more clever way to do that? I really appreciate your time reading this. Thanks in advance, Rubens

    Database business sales regex question discussion

  • Generic data fetch with IDataReader [modified]
    R RubensFarias

    Hi there, I'm looking for some advise for a generic data fetch pattern for IDataReader I'm working on, as follow:

    // main load
    using(GenericDataReader reader = new GenericDataReader(cm.ExecuteReader()))
    {
    while (reader.Read())
    {
    orders.Add(reader.Get<Order>()); // "GetList" pattern
    //return new Order(reader); // "Get" pattern
    }
    }

    // generic reader; interface implementation removed
    public class GenericDataReader : IDataReader
    {
    // ... \\

    public T Get<T>(string name)
    {
        int i = \_dataReader.GetOrdinal(name);
        if (\_dataReader.IsDBNull(i))
            return default(T);
        else
            return (T)\_dataReader.GetValue(i);
    }
    
    public T Get<T>() where T : ILoadable, new()
    {
        T entity = new T();
        entity.Load(this, false);
        return entity;
    }
    

    }

    // All business objects must implements this interface
    public interface ILoadable
    {
    void Load(GenericDataReader reader, bool deep);
    }

    // Sample business object
    class Order : ILoadable
    {
    int id;
    Customer customer; // Note
    DateTime orderDate;
    DateTime requiredDate;
    DateTime? shippedDate;
    List<OrderDetail> orderDetails;

    public Order(){ }
    
    public Order(GenericDataReader reader)
    {
        Load(reader, true);
    }
    
    #region ILoadable Members
    
    public void Load(GenericDataReader reader, bool deep)
    {
        id = reader.Get<int>("OrderID");
        customer = reader.Get<Customer>(); // Note
        orderDate = reader.Get<DateTime>("OrderDate");
        requiredDate = reader.Get<DateTime>("OrderRequiredDate");
        shippedDate = reader.Get<DateTime?>("OrderShippedDate");
        if (deep && reader.NextResult())
        {
            orderDetails = new List<OrderDetail>();
            while (reader.Read())
            {
                orderDetails.Add(reader.Get<OrderDetail>());
            }
        }
    }
    
    #endregion
    

    }

    What do you think? Are there any major drawback with this model I'm missing? Are there any more clever way to do that? I really appreciate your time reading this. As long we come to a conclusion I'll write an article for CP with that we learned about it. TIA, Rubens EDIT: Added formatting

    modified on Thursday, March 20, 2008 6:44 AM

    C# business sales regex question discussion
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups