EF4 code only - How do I change column order? - entity-framework-4

I setup the builder and used CreateDatabase to generate the database.
However the table columns created are ordered alphabetically. Is there a way to control the order?

As far as I know, code only doesn't have support to such feature.
Edit: The new CTP5 has an attribute called ColumnAttribute with some features like Order.
Hope it helps.

Related

Entity Framework 6 pluralises tablename when not required

I am using EF 6 and code first in my application.
I have a table called FaultClosedBy created by Code First.
However in my code where I want to do a simple query of the table, it is looking for a non-existent table called FaultClosedBies.
So how do I fix this?
See
Ivan Stoev got the right answer in his comments under my question:
"Apply [Table(FaultClosedBy")] data annotation on FaultClosedBy class or modelBuilder.Entity().ToTable("FaultClosedBy");"

How to store item of nested sortable item in database?

I have requirement like this.I can drag and drop my one Order list to another.
and Save also into Data base.
Again when reload same format will be display.
I want to store Parameter like
DocumentCategory,
DocumentName,
Ordering
any one can give the idea class structure and table structure?
This really depends on the database you're using. However, if you decide to use MySQL, you can use this library that I put together recently to automate the whole process of storing/retrieval of user-defined classes. It also contains support for nested classes. Hope this helps!

Entity Framework 4 - update/insert views

My EF schema has a mixture of tables and views from my database. My view entities are all read-only, I want to be able to update/insert into these entities. I've tried the following post without any luck:
http://smehrozalam.wordpress.com/2009/08/12/entity-framework-creating-a-model-using-views-instead-of-tables/
Anyone have another ideas/pointers - this must be doable.
cheers
David
Generally the post is correct. Using views in EF is hard. Another trick is first using tables to define your model and then replace tables in database with views with same names as tables.
Have you tried Instead of Triggers?
http://www.codeproject.com/Articles/236425/How-to-insert-data-using-SQL-Views-created-using-m

How to make UPDATE queries in LINQ to SQL?

I like using LINQ to SQL. The only problem is that I don't like the default way of updating tables.
Let's say I have the following table with the following columns:
ID (primary key), value1, value2, value3, value4, value5
When I need to update something I call
UPDATE ... WHERE ID=#id
LINQ to SQL calls
UPDATE ... WHERE ID=#id and value1=#value1 and value2=#value2 and value3=#value3 and value4=#value4 and value5=#value5
I can override this behavior by adding
UpdateCheck=UpdateCheck.Never
to every column, but with every update of the DataContext class with the GUI, this will be erased. Is there any way to tell LINQ to use this way of updating data?
I'm confused by this statement:
but with every update of the DataContext class with the GUI, this will be erased. Is there any way to tell LINQ to use this way of updating data?
By "the GUI", do you mean the Linq to SQL designer? Because the property sheet for each member has an "Update Check" property that you can set to "Never". If you are manually editing the .designer.cs file, don't do that, instead change the Update Check setting in the actual designer.
Designer Screen http://img29.imageshack.us/img29/7912/updatecheckdesigner.png
Please note: The "default way" of updating used by Linq to SQL is called optimistic concurrency, and is a way of preventing conflicting updates from multiple users. If you turn this off by using the method above, you have to be prepared to deal with the fact that if two users have the same record open at the same time, the second user's changes will overwrite the first user's changes without any warning or confirmation. Be sure that this is the behaviour you really want.
Unfortunately, no, there's not. You have to edit the DBML manually after it is generated (or updated) - which is a pain (or use the Designer as already mentioned in the other answer).
When I last used L2S on a project, I wrote a quick utility which ran post-generation and fixed it up, but it's an unnecessary pain which (c)shouldn't be required IMHO.
Ran into this one myself. The trick is to change the way one generates the DBML--such as using l2st4. Then you can set that pesky UpdateCheck property to always be never by modifying the template.
That is how Linq works. Why don't you like this update behavior?
Read about optimistic concurrency
http://msdn.microsoft.com/en-us/library/bb399373.aspx

Showing many tables in many dropdown lists. c#, asp.net-mvc, linq2sql

I want to use an example to explain what I want.
Assume I've following DB design:
Item (id, name, categoryID);
Category (id, name);
When user wants to create an Item (fill in form), I'll give a list of categories in a dropdownlist, and when user chooses one of the categories ASP.NET MVC will automatically bind categoryID, to the selected one. I need to present same dropdown list when editing the item with correct selected one.
Question:
But my DB is very big, and it requires around 30-40 (maybe even more) category-like tables, that contain just "id" and "name", and all tables need to be shown in dropdown list while creating some other object, and also needs to be presented while editing the object. Definitely above schema doesn't work, because it's tedious to write same logic 100 times with just different table names. (I'm using Linq2SQL)
Currently my solution is:
Make a view that's based in all such tables and in application I just call a function that construction dropdownlist from that single view. But it's still tedious to change view definition everytime I add a new table.
Do you guys think of a better solution for this tedious work, possibly using reflection or some other tecnologies.
It is not a problem "Definitely above schema doesn't work, because it's tedious to write same logic 100 times with just different table names."
If I were you, I will mark an addition interface on these class using "partial class" feature.
Then, I will write few extension method for the partial class.
If anyone interested in the solution:
I've used reflection to solve this problem.
I use reflection over DataContext to get the Table (by string name), and get its fields and construct the optionlist.

Resources