0

My system has this pattern DAO->Objects->facade->View

so i have a DAO to query database, and instantiate objects, this objects has only attributes (just a container / entity), i want to use LINQ in DAO part, but i dont realize how to pass my objects becouse LINQ generate 1-per table.

namespace ykpObjects.Objects
{
public class Customer
    {
        public string name { get; set; }
        public Cidade()
        {
            cidadeID = 0;
        }
    }
}

namespace ykpData.Components.MSSQL
{

    public class CustomerDC : DataComponentCM, ICustomerDC
    {

        Customer ICustomerDC.RecuperaPorID(int CustomerID)
        {
            Customer Customer = new Customer();

            using (MDDataContext omd = new MDDataContext(base.PreencherConexao()))
            {
                sp_mkp_Customer_SelectByIDResult result = omd.sp_mkp_Customer_SelectByID(CustomerID).SingleOrDefault();
                if (result == null)
                    return null;

                Customer.name = result.name;


                return Customer;
            }
        }
    }
}

I use DAO to call sprocs, so i get sproc results and instanciate a object of Customer for exemple, and pass this to control, now i want to change to linq but i dont wanna change all object structure to minimalize the impact.

Any advice ?

3
  • The Objects section of your design does not mean anything to me. Please elaborate. Commented May 7, 2011 at 23:35
  • 1
    Please clarify your question. Commented May 8, 2011 at 0:11
  • I use DAO to call sprocs, so i get sproc results and instanciate a object of Customer for exemple, and pass this to control, now i want to change to linq but i dont wanna change all object structure to minimalize the impact. Commented May 8, 2011 at 0:17

1 Answer 1

1

I'm not exactly sure what you are talking about with your current setup, but I think you're asking how to re-use the objects you currently have with Linq to SQL, rather than generating new ones from a dbml file. Am I right?

If so, you have a few options. You can use attributes to decorate your existing objects so that you can populate them with L2S, or you can create mapping files.

Some info here: http://www.sidarok.com/web/blog/content/2008/10/14/achieving-poco-s-in-linq-to-sql.html

I use Linq to SQL with attributes to achieve a "code first" solution, here's an example class:

[Table(Name = "Countries")]    
public class Country
{
    [Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
    public int CountryId { get; set; }

    [Column]
    public string iso2 { get; set; }

    [Column]
    public string iso3 { get; set; }

    [Column]
    public string name_en { get; set; }
}

To work with this object:

var context = new DataContext(ConnectionString);
var data = context.GetTable<Country>().Where(c => c.CountryId == 1);
Sign up to request clarification or add additional context in comments.

1 Comment

Exact !, one more question, how i set the database for this objects ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.