tags:

views:

23

answers:

1

Hey i am looking for a lib that can take the class below and generate these two tables with a reference/foreign key and allow me to tweak the default logic. Like below, unless i specify otherwise when i do sqlClass.Insert(imglist) it will not create another entry for user_id but try to find an existing one in the database.

    class image_list
    {
        public PK id;
        [InsertOrSelect]
        public name_list user_id;
        public long pic_id;
        public string link;
    }
    class name_list
    {
        public PK id;
        public UniqueString username;
    }
A: 

If you design your tables using the LINQ-to-SQL ORM you can use the generated DataContext object to create a database containing the schema you designed. The method is called DataContext.CreateDatabase

Aviad P.
sounds like i can get the schema but can not get the queries with LINQ-to-SQL?
acidzombie24
If you mean also to automatically create stored procedures, then no. But if not, what do you mean by queries? LINQ-to-SQL doesn't use queries explicitly, you simply access properties (which may refer to foreign-key records) and the query provider fetches them for you transparently.
Aviad P.
interesting, what happens when i write imglist.user_id = new name_list(); imglist.user_id.username = "username1"; I dont think linq to sql will insert/write the data until i ask it too? (I am thinking about incomplete class data and not null values). How would i insert imglist and would it automatically try to insert user_id since it is a reference? Will it try to find if that user exist (by searching the unique string username since it is set and PK id isnt)?
acidzombie24
LINQ to SQL handles that just fine. It was designed for all these scenarios. But you need to read about it.
Aviad P.