I am creating a model from an existing DB using EF5 with a table containing a geography column. The model for the table works perfectly fine. However if I try to map a stored procedure which simply selects the geography column I cannot map this column in a Function Import. In the Column Information the EDM Type is set to "Not Supported". However the model maps the geography type as a parameter without a problem.
IDE is VS2012 Premium, framework .NET4.5
Any idea's?
I ended up creating the complex type without the my geography column through function import and afterwards added the scalar property of type Geography. Though it wouldn't automatically map the column for me. So I looked through EDMX with the XML editor looking for the mapping details for the function and added the mapping information manually. After that everything worked fine.
Oké, so I found one way to answer this myself. To anyone interested: I've manually created a new Scalar Property of the Geography type on the complex type which results from the SP. Now somehow the value maps. Looks to me the editor is not able to create a property, but mapping an existing property is no problem. To me this seems like a bug in the editor.
Also have a look at this thread: Build error when using VS 11, .NET 4.5 and Entity Framework
Related
I am working with entity framework 6 with database 1st approach. I changed the datatype of my columns in the table and after updating my model I got the following error:
Error 1 Error 2019: Member Mapping specified is not valid. The type
'Edm.Int32[Nullable=False,DefaultValue=]' of member 'Warranty' in type
'pjModel.Bill' is not compatible with
'SqlServer.nvarchar[Nullable=False,DefaultValue=,MaxLength=50,Unicode=True,FixedLength=False]'
of member 'Warranty' in type 'pjModel.Store.Bills'.
what I understand that there is some compatibility issue between datatypes of framework and sql server.
Also when I opened the .edmx file with XML viewer, it clearly shows that changes are propagated in the model i.e data type has been updated, but in the diagram view when I right click the particular column it still shows the old datatype.
I can provide more information if required.
The issue has been resolved. I manually change the type from the diagram view and then it get mapped with the model class.
Same problem here, using EF6, after changing on a database table a field from int to bit.
It was not enought to delete property from model designer, and create it again, as the table mapping refered to the old type.
I guess this could be useful for similar cases. The only way to solve it (unless you don't mind deleting entity and updating model from database) is to edit your Entity Data Model as text (by default, DataModel.edmx), locate the entity as <Entity> node inside <Schema> node and find the desired property that indicates the old type. As an example:
<Property Name="MyProperty" Type="int" Nullable="false" />
Simply change Type attribute to the desired type, return to Visual Studio, save the edmx file, and rebuild.
I can't find any info about this in the documentation, so I will ask here. How does breeze handle database column defaults? I have required columns in my database, but there are also default static values supplied for these in the database column definitions. Normally, I can insert null into these columns, and the new records will get the default. However, breeze doesn't seem to be aware of database column defaults, and the entities that have null in these columns fail validation on saving.
Thanks,
Mathias
Try editing the edmx xml by adding StoreGeneratedPattern = "Computed" attribute to the column with default value in the DB.
Edit:
Actually, before doing editing the xml, try setting the StoreGeneratedPattern property to Computed in the model editor itself.
Update:
This was fixed in Breeze 1.4.6 ( or later), available now.
Original Post:
There is currently in a bug in Breeze that should be fixed in the next release, out in about week. When this fix gets in then breeze will honor any defaultValues it finds in the EntityFramework data model.
One problem though is while it is easy to get 'defaultValues' into a Model First Entity Framework model via the properties editor, it's actually difficult to get it into a Code First EF model, unless you use fluent configuration. Unfortunately, EF ignores the [DefaultValue] attribute when constructing Code First model metadata.
One workaround that you can use now is to poke the 'defaultValue' directly onto any dataProperty. Something like:
var customerType = myEntityManager.metadataStore.getEntityType("Customer");
var fooProperty = customerType.getProperty("foo");
fooProperty.defaultValue = 123;
I'm using Self Tracking Entities that implements IObjectWithChangeTracker with the last Entity Framework RC available as a Nuget. The target database is PostgreSQL. I'm also using Code First fluent API to construct the model and LINQ to Entity for querying the database.
To my surpise, a simple SELECT query on the entity generates a SQL query with a mysterious column ChangeTracker_ChangeTrackingEnabled that does not exist in the datatable ! I do not understand this behavior as it seems to me that the EntityTypeConfiguration derived class maps the entity properties to the datatable columns in its constructor.
Is there a way to disable this behavior or at least tell which column should be mapped by the change tracker ?
For that purpose, Context.Configuration.AutoDetectChangesEnabled = false or calling IsConcurrencyToken() mapping in the EntityTypeConfiguration derived object does not help.
Any help appreciated.
TIA.
You must inform EF about every public property you want to avoid in mapping by either marking property with NotMapped attribute or by using Ignore in fluent API.
Btw. as I know STEs are not designed to be used with code first or DbContext API.
I have an entity/table that uses sqlgeography.
Since EF 4.X doesn't support spatial types I'm instead sending the bytes of the field back and forth.
I have stored procs on the database side that handles the converstion and properties on the code side to do that job.
To add the properties in the code I used a partial class.
One of those properties is for the SqlGeography which simply wraps around the byte[] property to handle getting and setting.
This property is hidden from EF using the NotMappedAttribute.
The other is the property exposing the byte[] itself and is decorated with the EdmScalarPropertyAttribute and DataMemberAttribute.
I then go to the EF model designer (*.edmx) to point the entity model at the Insert/Update/Delete stored procs.
It finds the stored procs alright and realises that they (when appropriate) take a VARBINARY parameter.
It also has a drop down allowing you to select a property on the entity class which maps to that parameter.
However this drop down doesn't list either of my properties. I don't care about the SqlGeography property since that is meant to be hidden from EF, however it is vital for me to be able to point it at the byte[] property, as that is where the data comes from.
I would very much like to avoid database triggers or wrapper classes and addiitonal fields to fudge this in to working.
I tried manually editing the .edmx file to include the byte[] property, but then it just complains it's unmapped.
Can anyone give me some insight in to how to get this to work? Or an alternative method of achiving the end result?
We could use a view to create the binary field for us, but this then involves manually creating a lot of the xml for the relationships within the data.
This pretty much voids the point of using EF which is to make life simple and easy.
For this project We'll just add a binary field to the table then have sprocs to handle the converstion on the server and a property in a partial entity class for exposing the geography type in the model.
Next project I doubt we'll be using EF. Dapper is so much more painless, even if theres a touch more code writing involved.
Here's the links for using views if anyone thinks it would be applicable to them:
http://thedatafarm.com/blog/data-access/yes-you-can-read-and-probably-write-spatial-data-with-entity-framework/
http://smehrozalam.wordpress.com/2009/08/12/entity-framework-creating-a-model-using-views-instead-of-tables/
In the end we created a computed column for each table that exposes the spatial data as bytes.
We then use stored procs for inserting and updating the spatial data.
I have an Entity-class having a Property of type Int32: on generating DDL using DevArt for ORACLE a NUMBER(10) column is generated. Reading and writing instances works flawlessly.
However, on fetching instances of this Entity-class sending a custom query to ExecuteStoreQuery on the ObjectContext this Property seems to be returned as System.Double, as such constructing the instances fails.
Can I hint DevArt to construct System.Int32?
Thank you.
Bart
The reason is the fact that OracleDataReader, which is used in the ExecuteStoreQuery method, has type mapping different from the one used in the Entity Framework provider.
I recommend you to use NumberMappings, I suppose you will need to map Number(10) to Int32: Number Mappings=((NUMBER,10,10,System.Int32). These changes should be persisted to the model connection string (they are duplicating the default EF mapping rules, it is necessary for the OracleDataReader from ExecuteStoreQuery).
Please let us know if the problem persists.