Entity classes decoupled from LINQ to SQL provider for implementing the Repository pattern. How?

前端 未结 9 534
不知归路
不知归路 2021-02-02 02:57

I have looked over the Repository pattern and I recognized some ideas that I was using in the past which made me feel well.

However now I would like to write an applicat

9条回答
  •  无人共我
    2021-02-02 03:28

    You can create an external XML file mapping the database to any class:

     
     
        
               
               
           

    And then pass the XML to a DataContext class:

     using (var cn = GetDbConnection())
      { var mappingSrc = XmlMappingSource.FromReader(xmlReader);
    
        using (var db = new DataContext(cn, mappingSrc))
         { var q = from entity in db.GetTable()
                   where entity.PropertyA = "..."
                   select entity.ID;
         }
      }
    

提交回复
热议问题