entity-framework-4

Delete child objects in Entity Framework

六眼飞鱼酱① 提交于 2019-12-20 16:22:22
问题 I'm using EF and when I do this: foreach (var reg in detail.Regs) { this.db.Regs.DeleteObject(reg); } I get this: Collection was modified; enumeration operation may not execute. What I'm I doing wrong here??? 回答1: The reason for that is because as you delete the objects from the context, EF is actively update the Regs navigation property count which means the detail.Regs collection is being changed during the foreach loop which always cause the exception you are getting. You can create a new

EF 4.0 Guid or Int as A primary Key

偶尔善良 提交于 2019-12-20 14:46:13
问题 I am Implementing custom ASPNetMembership using EF 4.0 Is there any reason why i should use Guid as a primary key in User tables? As far as i know Int as a PK on SQL Server more performanced than strings. And Int is easier to iterate. Also, for security purpose if i need to pass any int id somewhere e.g in url i may encrypt it somehow and pass it like a string with no probs. But if i want to use auto generated Guid on SQL Server side using EF 4.0 i need to do this trick http://leedumond.com

Best approach to Architect the integration of two separate databases?

孤街醉人 提交于 2019-12-20 12:39:31
问题 I've ran into the following questions at work, and I don't have the experience or knowledge in order to answer them, I'm hoping that some of you wiser folk may be able to point me in the right direction, any answers will be greatly appreciated! Scenario We have two aspects of the business using separate databases, Human resources and Operational Areas (Homecare). Human Resources keep track of the company’s employees, shift patterns, absence, pay etc. Homecare keeps track of client information

Entity Framework 4 and WPF

让人想犯罪 __ 提交于 2019-12-20 09:41:14
问题 I am writing a WPF application, using an MVVM design with Entity Framework 4 as the ORM. I have collection properties in my view model that will contain collections of entities returned from EF4 as IEnumerable<T> collections in response to queries submitted from the business layer. I had hoped to simply wrap the IEnumerable<T> result set in an ObservableCollection<T> . However, I found myself writing change-tracking code in my repository, or maintaining shadow collections of changed objects,

DisplayFormat Dataannotation not working

纵然是瞬间 提交于 2019-12-20 07:29:44
问题 I have following dataannotation in my model class: [Required(ErrorMessage = "Required")] [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")] public DateTime DateOfBirth { get; set; } and when I use following in my view, I dont get validation error: <tr> <td>@Html.LabelFor(x => x.DateOfBirth, new { @class = "lbl" }, "Date Of Birth") </td> <td>@Html.TextBoxFor(x => x.DateOfBirth, new { @class = "w100 _dob" }) <br>@Html.ValidationMessageFor(x => x.DateOfBirth) </td

How to update entity?

痞子三分冷 提交于 2019-12-20 05:48:05
问题 I had a question more detailed earlier which I had no answer, I will have the same question with a simpler way: I have an EF database with foreign key to another table. I would like to UPDATE an ENTITY . But I need to this like this and I'll write the codes below: Go to database and retrieve the Member by id, return EF Member object Do some changes on the object OUTSIDE the EF Context Send the MODIFED EF Member into a Save method In BL layer save method uses the context and save changes. 1)

How can I execute an Oracle function from within a LINQ expression in Entity Framework 4?

最后都变了- 提交于 2019-12-20 04:59:08
问题 I am using Visual Studio 2010, C#, Entity Framework 4 and Oracle 10g. I need to be able to return the result of a database function as a scalar property of an anonymous type. My Oracle schema has two tables, PARENT and CHILD, and a function FNC_ADD. I have created an entity model using the Visual Studio ADO.NET Entity Data Model template, including both tables and the function. The StorageModels section of my .edmx file looks like this: <!-- SSDL content --> <edmx:StorageModels> <Schema

Create Views for object properties in model in MVC 3 application?

给你一囗甜甜゛ 提交于 2019-12-20 04:50:54
问题 I have an Asp.Net MVC 3 application with a database "Consultants", accessed by EF. Now, the Consultant table in the db has a one-to-many relationship to several other tables for CV type information (work experience, etc). So a user should be able to fill in their name etc once, but should be able to add a number of "work experiences", and so on. But these foreign key tables are complex objects in the model, and when creating the Create View I only get the simple properties as editor fields.

MVC updating .edmx files (.msl, .csdl, .ssdl)

我与影子孤独终老i 提交于 2019-12-20 04:34:45
问题 I have 3 .edmx files (.msl, .csdl, .ssdl) in my root project directory where the web.config is. Why are these not updating when I do a 'update model from database'? I have to manually add the new fields to these files... 回答1: .msl, .csdl and .ssdl are result of .edmx compilation, if you do not embedd them into assembly check that "EntityDeploy" is selected for "Build Action" in .edmx file properties (in Solution Explorer) and "Copy to Output Directory" is selected for "Metadata Artifact

Entity Framework code first aspnet_Users mapping / joins

青春壹個敷衍的年華 提交于 2019-12-20 04:24:09
问题 I was wondering with Entity Framework 4.1 code first how do you guys handle queries that involve an existing aspnet_Users table? Basically I have a requirement for a query that involves the aspnet_Users so that I can return the username: SELECT t.Prop1, u.Username FROM Table1 t INNER JOIN aspnet_User u ON t.UserId = u.UserId Where t.Prop2 = true Ideally in linq I would like: from t in context.Table1 join u in context.aspnet_Users on t.UserId equals u.UserId where t.Prop2 = true But I'm not