ef4-code-only

DbContext SaveChanges Order of Statement Execution

ε祈祈猫儿з 提交于 2019-11-28 07:14:09
问题 I have a table that has a unique index on a table with an Ordinal column. So for example the table will have the following columns: TableId, ID1, ID2, Ordinal The unique index is across the columns ID1, ID2, Ordinal. The problem I have is that when deleting a record from the database I then resequence the ordinals so that they are sequential again. My delete function will look like this: public void Delete(int id) { var tableObject = Context.TableObject.Find(id); Context.TableObject.Remove

How to accept JSON in a WCF DataService?

不想你离开。 提交于 2019-11-28 04:58:11
问题 I'm trying to understand how to use WCF Data Services (based on EF 4.1) to create a restful web service that will persist entities passed as JSON objects. I've been able to create a method that can accept a GET request with a set of primitive data types as arguments. I don't like that solution, I would prefer to send a POST request with a JSON object in the http request body. I've found that I can't get the framework to serialize the json into an object for me, but i would be fine with doing

How not persist property EF4 code first?

穿精又带淫゛_ 提交于 2019-11-27 22:38:54
How do I make non persisted properties using codefirst EF4? MS says there is a StoreIgnore Attribute, but I cannot find it. http://blogs.msdn.com/b/efdesign/archive/2010/03/30/data-annotations-in-the-entity-framework-and-code-first.aspx Is there a way to set this up using EntityConfiguration? In EF Code-First CTP5, you can use the [NotMapped] annotation. using System.ComponentModel.DataAnnotations; public class Song { public int Id { get; set; } public string Title { get; set; } [NotMapped] public int Track { get; set; } Currently, I know of two ways to do it. Add the 'dynamic' keyword to the

How map objects to a view with EF 4 code first?

二次信任 提交于 2019-11-27 22:00:20
How can you map an entity to a database view with EF 4 code first? Is there a way to do this by deriving from the EntityConfiguration classes? Yes! I found the answer: You can certainly use Code First to map to a view, just tell Code First that it's a table and it will use the same SQL against the view that it would for a table. Obviously if your view isn't writeable then saving is going to fail if you try and update values in the entities that are based on the view, but we will just delegate to the database so if you don't update these entities then you won't have any issues. http://social

How do I map a char property using the Entity Framework 4.1 “code only” fluent API?

混江龙づ霸主 提交于 2019-11-27 14:16:09
I have an object that has a char property: public class Product { public char Code { get; set; } } Entity Framework doesn't seem to be able to map chars (this field is missing from the database when I create the database schema from my model objects). Is there anyway I can map the char (e.g. to a string) using the fluent API? I don't want to change the model objects as they are part of a legacy shared library. Ladislav Mrnka Char is not valid primitive type for entity framework = entity framework doesn't map it. If you check CSDL reference you will see list of valid types ( char is not among

How do I map a char property using the Entity Framework 4.1 “code only” fluent API?

回眸只為那壹抹淺笑 提交于 2019-11-26 18:23:22
问题 I have an object that has a char property: public class Product { public char Code { get; set; } } Entity Framework doesn't seem to be able to map chars (this field is missing from the database when I create the database schema from my model objects). Is there anyway I can map the char (e.g. to a string) using the fluent API? I don't want to change the model objects as they are part of a legacy shared library. 回答1: Char is not valid primitive type for entity framework = entity framework doesn