i want to let the user select atable and then select only some columns of this table with specific order then export the data to csv file
also the user can import from csv file

it is easy by direct way with dynamic sql statements but how can i do that with dataobjects

asked Jul 11 '11 at 02:30

mnady's gravatar image

mnady
5111


One Answer:

Hello mnady,

First, you will need a domain model for your database, so every table must be described as a separate persistent type (entity).

Second, when you get a list of columns to export, you do the following:

 List<string> columns; // a list of columns to export

 using (var session = Domain.OpenSession()) {
    using (var t = session.OpenTransaction() {

        var items = session.Query.All<Customer>();
        foreach (var item in items) {
            var values = new List<string>();
            foreach (string column in columns) {
                values.Add(item[column]).ToString();
            }
            cvsfile.AddLine(values.Join(','));
        }
        t.Complete();
    }
 }

The import routine is the opposite to this one.

answered Jul 11 '11 at 05:39

Dmitri%20Maximov's gravatar image

Dmitri Maximov
22111211

Thank you for your answer but how to make (Query.All<customer>();)

Customer is string variable with me how to put it in the above query

thanks

(Jul 14 '11 at 06:17) mnady mnady's gravatar image

Hello mnady,

Try this one:

var typeName = "Customer";
var type = Type.GetType(typeName);
var items = session.Query.All(type);
(Jul 14 '11 at 09:40) Dmitri Maximov Dmitri%20Maximov's gravatar image

Thank You For Your Help

(Jul 17 '11 at 07:29) mnady mnady's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×5
×2
×1

Asked: Jul 11 '11 at 02:30

Seen: 1,636 times

Last updated: Jul 17 '11 at 07:29

powered by OSQA