How to automatically create a class compatible with an access table?

I want to use Linq to connect to the access2007 database (I do not want to use ado.net).

I saw some examples, but they all create an object class that I want to import from the database, for example

public class Company { public string Name { get; set; } public List ListEmp { get; set; } } var EmpDetails = from comp in ListCompany select new { Emp = (from emp in comp.ListEmp select new { Company = comp.Name, emp }) }; 

This is easy when I have a small database, but I have a database with 30 attributes in the table, so it will be difficult to make a class specifically for the object from the table

as simple as automatically creating an object compatible with objects from a table

If I were unclear, tell me so that I can clarify it.

thanks

+4
source share
2 answers

First, note that LINQ-to-SQL is not (AFAIK) approved for use in Access. It generally works, but MMMV.

Personally, I would like to approach this by importing (transferring) tables from an Access database into an instance of SQL Server Express and using this to generate a model (of course, the tool can even work against Access, but I assume that they donโ€™t - that is the question). With the created model, you must specify it (at runtime, through the connection string or connection) in your access database.

You might also think: why not leave it as a SQL Server Express node - it works well and is better supported in terms of LINQ-to-SQL.

Also note that there are other tools similar to LINQ-to-SQL that may work for your purposes; DbLinq, dapper-dot-net, etc. - and some more heavy tools (EF, NHibernate, LLBLGen Pro, etc.)

+1
source

XPO , ORM from Developer Express , lets you create .Net classes directly from the Access 2007/2010 database and use Linq to create queries.

Itโ€™s good that if you want to change the database backend, for example, say that you transferred your data from Access to SQL Server or MySQL or PostgreSQL, etc. you just need to change the database connection string, not the code.

Documentation is available online .

+1
source

All Articles