entity-framework-4

Generating Entity Keys

邮差的信 提交于 2019-12-07 18:19:52
问题 I have run into my first dissapointment with Entity Framework 4. It turns out that SQL CE, when used with EF4, does not support autogenerated primary keys. I get a System.Data.UpdateException from OnjectContext.SaveChanges() with this message: Server-generated keys and server-generated values are not supported by SQL Server Compact. So, now I have to manually generate keys for my entities. Assuming I want to use auto-incremented integer keys, what is the best way to go about generating and

Correct way to pass Entity objects between layers?

二次信任 提交于 2019-12-07 18:08:31
问题 I am just learning the Entity Framework and have made some good progress on incorporating it with my layered code structure. I have 2 visual layers, a business layer and a data access layer. My problem is in passing entity object between layers. This code sample does not work: // BLL public static void Test1() { List<User> users = (from u in GetActiveUsers() where u.ID == 1 select u).ToList<User>(); // Do something with users } // DAL public static IQueryable<User> GetActiveUsers() { using

Populate a dropdown list from db

五迷三道 提交于 2019-12-07 16:36:31
问题 I have an mvc 3 application with 2 tables in my entity framework. PurchaseTable which was PurchaseID,PurchaseDate & ProductID I have another table called Product which contains ProductID and ProductName. creating a new view to insert a new purchase how do I change the textbox in the view for ProductID to be a dropdown bound by the ProductName in the Product table? 回答1: Create a ViewModel: public class CreatePurchaseViewModel { public Purchase Purchase { get; set; } public IEnumerable

How to get rid of 'property could not be set to a double value, you must set this property to a non-null value of type decimal'

安稳与你 提交于 2019-12-07 16:00:43
问题 I'm trying to get a function import to work correctly. EF calls out to my stored procedure, but the result has an inner exception that I don't understand: var result = context.SomeFunctionImport(); I get: The 'Cnt' property on 'SomeClass' could not be set to a 'Double' value. You must set this property to a non-null value of type 'Decimal'. Here's the Cnt property on SomeClass : [DataMember] public Nullable<decimal> Cnt { get { return _cnt; } set { if (_cnt != value) {

Return Entity Framework objects from WCF

别说谁变了你拦得住时间么 提交于 2019-12-07 14:52:58
问题 I am working on a WCF service to provide data to multiple mobile clients. Data model is Entity Framework 4.0. Schema is given below. When i returnt he object of SysUser the result also contains the navigation properties and EntityKey and other EF related stuff. Is it possible that i get the pure object(only the database fields without the relationship etc). Thanks Update the exception occures "Only parameterless constructors and initializers are supported in LINQ to Entities." on followign

Entity Framework persisting child collection sort order

牧云@^-^@ 提交于 2019-12-07 13:34:21
问题 In NHibernate I can map a collection as a List to persist the order of the collection to the database. I'm using EF Code First (CTP4). How can I persist the sort order of a child collection (IList) without exposing the relationship in my domain model? 来源: https://stackoverflow.com/questions/4327281/entity-framework-persisting-child-collection-sort-order

How do I avoid a circular reference while serializing Entity Framework class

那年仲夏 提交于 2019-12-07 13:28:25
I have an MVC-3 (RC1) application using Entity Framework 4. I wish to return a JSON object from a controller action. This object is referenced by other objects, which obviously return the reference. I thus receive the following circular reference error: Server Error in '/' Application. A circular reference was detected while serializing an object of type 'Application.Models.ReferenceObject'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Table not mapped to Entity Framework Data Model

血红的双手。 提交于 2019-12-07 12:04:05
问题 Hi I'm back with another question,I have started using EF and I'm having problem with it. OverView: I made an EF model ,and found out that one table (named UserRoles) didn't showed up in the EF Model Diagram ,I tried to add it through "Update data model" ,but wizard didn't showed me that table to add (as if it was already added) ,I also tried to refresh model through "Update data model" wizard it was not helpful. Problem Explained: The original DB Diagram. Partial EF Model Diagram I tried to

LINQ expression that contains references to queries that are associated with different contexts

旧街凉风 提交于 2019-12-07 10:29:14
问题 I have this query: var list = (from t1 in context1.SomeTable join t2 in context2.SomeTable on t1.ID equals t2.ID where //some where clause select new { t1.SomeField, t2.SomeField }).ToList()); I will get this error when this query tries to execute: The specified LINQ expression contains references to queries that are associated with different contexts. Why is this not allowed with LINQ to Entities ? Is it still possible with LINQ to Entities in another way? What would be a work around for

Is there an easy way to verify whether or not the database schema is exactly what I expect it to be using Entity Framework?

﹥>﹥吖頭↗ 提交于 2019-12-07 10:15:21
问题 I want my application to verify database consitency at startup time. Is there an easy way to verify whether or not the database schema is exactly what I expect it to be using Entity Framework? EF4 itself does some verification. If a mapped type contains a column that does not exist in the target table, when EF4 is materializing it triggers an exception. Fine. However there are some things it does not do: It does not verify the entire database at first. It does not trigger an exception when