Entity Framework 6 pluralises tablename when not required - entity-framework-6

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");"

Related

Update model class name in EntityFramework

I have one table in the database with the name "Users", a year ago one of the developers added a model using database-first approach, and I don't know which entity framework version they used.
Now i want to change some of the fields datatypes in SQL.
The problem is that I am not able to update model using the refresh window and also tried to delete model and add it again, but after that there was a name that has been changed in Users to User.
The current entity framework version is 6.1.3
Just go to your DataBase.edmx and right click "Update Model from Database..." and then refresh the tables
For the table name check link please -> What is the meaning of the "Pluralize or singularize generated object names" setting?
And Ricardo has already written the update.

Entity Framework and LLBLGen

I have a database, which has two tables.
The Order table, and the Item table. The relationship is m:1.
I am using LLBLGen as the mapping tool to generate the source file.
I can see that the ItemID from the Item table is displayed in the Order entity from the designer of LLBLGen, which is correct.
However, when I try to call this generated source codes, the ItemID is not listed as a property of my Order class. Actually all my foreign key is gone.
Could anyone teach me how to generate the foreign key as a property?
Thanks a lot
It's a setting. Go to:
Project properties -> Output Setting values Tab -> EmitForeignKeyFields, check the checkbox. Ok -> regenerate code.
It's false by default.
Ps: if you post your question on our own support forums, you might get answers more quickly ;)

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

EF4 code only - How do I change column order?

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.

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

Resources