xtragrid binded to entity framework - xtragrid

my working environment is C#, Visual Studio 12, entity framework 5 DBContext, SQL Server 2008R2.
the generated entities sets are generated as Hash sets.
xtraGrid.DataSource = _order.OrderLines;
when I type data in the new row, data disappears when focus lost.
With using older entity framework, this logic was working.
What type should I choose for my entity set in order to solve my problem.
Thanks.

I changed type from HashSet to BindingList, and it works, God thank you.

Related

always seeing an empty database after running my application

I am using Vb 2010 in designing my apps. I've connected my database with my application but I didn't use any code in the connection. I used Data source and Databinding property and when I save the data the database is always empty. Please help me with a solution.
Place a BindingNavigator component in your form and set it's binding source property to the same datasource of your other component.

entity framework error after attached .mdf file

I attached an .mdf file in SQL Server 2008 and used that database for my entity framework database first project. Below is the error I got
Exception Details: System.Data.MappingException: Schema specified is not valid.
Error 2062: No mapping specified for instances of the EntitySet and AssociationSet in the EntityContainer"
I tried this link: How do I correctly set an association between two objects in the Entity Framework 4 Entitydesigner?
but it did not work for me. can anyone help me what can be the problem.
thanks,
michaeld
This exception usually occures if you have an entity in your model which doesn't mapped to a table (or an object) into the Database.
If you want that your project just starts debugging, Remove all entities from your model, Right-click in model designer and choose Update model from database
If you have an entity which it supposed to be mapped to a table into database, you should create a relative table in database, and map your entity to that table. You also can ghange your approach from db-first to code-first and enable migrations so that EF updates your db according to your model.
If you have an entity and you want to map it to a stored procedure in your db, see here

EntityKey properties of type “Geography” not supported. Entity Framework 5, VS 2012 – Database First

Created a SQL Server 2008 database and table with a property called “Coordinates” of type “geography”. In VS 2012 created a project, added references to Microsoft.SqlServer.Types and EF V5. Then, using the ADO.NET Entity Data Model wizard generated the edmx. When I compile in VS 2012 I get the following error:
Error 4 Error 129: The property 'Coordinates' in EntityType 'DBModel.GeoDestination' is not valid. EntityKey properties that are of type 'Geography' are currently not supported.
Many of the samples on the web are “code first” examples that use the type “DbGeography” as a type in their c# code and generate the database from the code resulting in a table with a property of type “geography”.
How do I do this database first and fix up the type? It does not appear that “DBGeography” is in the drop down list of types when using the “Table Mapping” view.
Using EF 5, NET 4.5, VS 2012 SP 1, SQL Server Types
I figured this out. Looks like a bug in the wizard. If the table in SQL does not have a primary key, the wizard automatically generates a key(s) in the resulting EF model. It appears random, sometimes one key is generated and sometimes it makes several properties keys. A Geography data type cannot be a key. It was not a key in the table, but the wizard made it a key.
Hope this response helps others.

Web Api and Odata without Entity Framework

I am having trouble getting OData to work with Asp.Net Web Api when the underlying data is NOT coming from Entity Framework.
I am using the latest OData Nuget package (Microsoft ASP.NET Web API OData 0.2.0-alpha release) but when I attempt to pass an OData query (say $top=10) I receive the error:
The given key was not present in the dictionary
If I don't send an OData query I can call the method just fine. The other methods in the same Web Api project that use Entity Framework work fine with OData queries. The one's that don't work are using Subsonic ORM to query an underlying AS400 data source. It returns an IQueryable. This worked just fine before the VS 2012 and .NET 4.5 RTM was released and OData was moved into a separate package. (i.e. worked with beta and RC versions of VS2012 and .NET 4.5)
Any ideas would be appreciated.
I guess this issue is caused by stable ordering, which doesn't work well with the underlying query provider. Could you put the call stack of the error to confirm it?
One big change with OData query composition in this release is that it ensures stable ordering before taking top items. The reason to do that is user may have random data source which makes return data keep changing.
The way web api odata package does is to add OrderyBy [Keys] query before executing top. Or if there is no key defined in the model (Keys are ID, EntityID, or [Key] attributed property), it will use all the primitive properties in the model to order.
If you can make sure that the data source will always return data with stable ordering, you can turn off this feature by code:
[Queryable(EnsureStableOrdering = false)]

Using Entity Framework with Oracle and Mapping Inheritance - Table-per-Type. Trigger updated Id is not being set in subclass table

I am using Oracle with Entity Framework. The database ids are generated using triggers and sequences.
I want to set up Table-per-Type inheritance, as described here. I've set the "CourseId" to be StoreGeneratedPattern of "Identity".
Everything seems to be fine, except when I insert a row. The table representing the base class (in the walkthrough linked above, the Course table) gets a generated ID as expected.
However the table representing the inherited class (in the walkthrough linked above, the OnlineCourse table) has a row inserted with the CourseId set to zero. This violates the foreign key constraint.
I assume it's something to do with the sequence of inserts. I imagine it should work like:
Insert the Course row
Retrieve the newly created CourseId value
Insert the OnlineCourse, using the new CourseId
However, this isn't working because it's just using the default value of the CourseId (zero) to insert into OnlineCourse.
Any ideas how to fix this?
Since #Campinho hasn't written up his suggestion as an answer, I will do it.
This article has some background on a bug in StoreGeneratedPattern in VS2010.
One of very important features in ORM tools is an ability to get data auto-generated by a database during the entity persistence back to your application. The Entity framework supports this feature by setting StoreGeneratedPattern in the configuration of persisted property. The StoreGeneratedPattern setting is available in both SSDL (Store schema definition language) and CSDL (Conceptual schema definition language) parts of the EDMX file. CSDL configuration allows you defining the reloading behavior in the Model-first approach but SSDL part is responsible for generating correct SQL commands which will persist the entity and reload auto-generated properties. Unfortunately for a long time this was the source of all problems.
The feature was very hard to use because of the annoying bug in the Entity designer. When we set the property in the designer, the value was saved only in CSDL part but not in SSDL part of the EDMX file and the feature didn't work until we opened the EDMX file as XML and manually modified SSDL part. This solved the problem but only until we updated our model from the database. The update always deleted whole SSDL part including our manual change so we had to do it again. Any incremental development of our models become a big pain. The workaround was using mapped stored procedures for inserting and updating entities and mapping result sets (returning auto-generated data) from these stored procedures back to the entity. Finally this bug is solved in Visual Studio 2010 SP1 and we can use StoreGeneratedPattern without any problems because the value is correctly set in both CSDL and SSDL parts and it is not overwritten during updating from the database.
If you have this problem install KB2561001.
I installed the hotfix and changed the StoreGeneratedPattern to "None" then back to "Identity" for the relevant Ids. I could clearly see the SSDL section had been updated to indicate the new setting.
Then everything just worked! I'm not sure what's going to be in the patch from Oracle that they think will fix the problem.
I filed a service request with Oracle and it turns out this is a bug in their provider.
BUG 13724992 - EF: ENTITY NOT UPDATED AFTER SAVECHANGES USING STOREGENERATEDPATTERN
A fix for this bug will be released in an upcoming patchset. However, which patchset in will be included in and when that patchset will be released is currently unknown. I will let you know as soon as this fix will be released.

Resources