Code First - how to create DB? - entity-framework-4.1

I use EF DB-First approach long time ago and like it. But right now I have to use code-first. I created my model, my context class, but how to create DB by classes right now?

Related

Using flat column or relationship in MySQL

I am designing a reward system for my game. I have a table called VirtualItem (VI) (key, display_name), the data contained could be (gd, gold), (dm,diomond). Then I have a Reward table (id, reward_items,etc)
Currently reward_items are a json array of VIs: [[{key: dm, count:5},{key:gd, count10]].There is a web portal allowing user to CRUD reward_items.
My question is, should I use the current flat structure, or add another layer in between and use reference in reward_items instead? Something like reward_items: set_id(referring VirtualItemSet table).
Apparently, using flat structure(json array) will make the query easy. But I probably also need to put dislay_name inside the JSON as well. In addition, when VI changes, its hard to update reward_items.
Using relationship makes the db schema more complex, and make backend operation on CRUDs operation of reward_items complicated as well.(need to create VirtualItemSet item on the fly etc). It also make query more complicated. But it will support dynamic change of VI.
Whats your opinion on this? Or there is a better database for this type of senario?
Thanks,
Chen
As you notice: If you use flat column you can't make sql join and keep data consistency by database for foreign keys. In my practice this decision always make problems in future. So i think better don't use flat columns.

Orange - Is it possible to create a new widget based on an existing diagram?

Let's say I have the following diagram:
I would like to encapsulate this entire diagram into one widget. Is this possible? (Sometimes I end up using the same diagram structure, and was wondering if I could turn that into a widget)
Like a "macro widget"? No. But you can save this schema and reuse it.

Adding tables via DAO to a database

As a general question which would really help me "connect the dots" with my studies.
I am currently doing exercises working with DAO and Learning how to add tables automatically. Although i have been working with databases for many years, i question, what type of scenerarios would it be vantagious to use this function. When is it necessary to add tables to a database in an automatic way? Up until now, in all my experiences the tables i need have Always been defined from the beginning and I cant think of a situation where I could of benefited from using this function. For example, i use frequently delete queries to help me clear tables and re-populate them, but when would it be necessary to actually "create" a new table"?
Yes, I have seen a scenario where new tables were created 'on the fly' (either via SQL create, or just DAO). With a shared database on a server, the application called for importing Excel data that a particular user was responsible for, so a table was created on the fly. Multiple users, changes in staff, need to keep data independent, etc. we could create their own table (name based on userid) that they had interfaces to do whatever they wanted with their own data. Not a typical scenario, but worked well for this application.

LINQ-to-SQL classes from a select statement

I am a little new to linq-to-sql. I was just thinking suppose you wanted a subset of fields (in your db table) to actually be a data model in your application, what do you do? What I have thought of so far is to create a view from the actual db table and build linq-able classes using it.
Or is there a better way of doing this?
try these Walkthrough: Creating LINQ to SQL Classes (O/R Designer)
or these implemented in MVC Creating Model Classes with LINQ to SQL
One option is you can create Anonymous Types and use it.

Linq2sql naming convention

I have just started using Linq2sql, it generates all of the Classes after my tables which is awesome. my problem is that i have a lot of objects that have the same name as my tables.
this is forcing my to fully namespace everything which i don’t really like as i think it makes my code look messy.
Has anyone found an elegant way to get around this?
ps: i know about namespace aliases and im not really a fan.
If this really is an issue for you, you can change the name of your generated table items in the Linq designer. Select the table and change the value in the Name field in the properties (L2S keeps track of the source table as a separate item, so the two don't have to be named the same). Note that regenerating your DBML file will wipe these changes out.
Along the lines of Rails convention (which I use in my .net) frequently I will name the database table the plural name and the class the single name eg. Table = Users vs. Class = User.
You could try turning off pluarisation of the names it generates.
Tools -> Options -> Database Tools -> O/R Designer