entity-framework-4

Cannot find Entity Framework 4 annotations

穿精又带淫゛_ 提交于 2019-12-23 12:24:54
问题 I'm trying to map a POCO class to a table of my DB using annotation. I need to use Table annotation to specify the name of my table, but I cannot resolve the Table annotation. Note: I imported System.Data.Entity namespace but It doesn't work. Which namespace do I have to import to use EF annotations? NOTE 1 I mean: [Table("my_table")] public class MyClass { // ... } NOTE 2 My Entity Framework dll is v4.0.30319 回答1: I need to use the Table annotation You need to import the System.Data.Linq

How to use Include and Anonymous Type in same query in Entity Framework?

穿精又带淫゛_ 提交于 2019-12-23 11:44:47
问题 In How To Count Associated Entities using Where In Entity Framework I get this query But when I access queryResult[0].post.Category or queryResult[0].post.Tags it´s always empty, because I am not using Include. Include dont work with Projection, as microsoft say at last item here: http://msdn.microsoft.com/en-us/library/bb896317.aspx var queryResult = (from post in posts join comment in comments.Where(x=> x.IsPublic) on post.Id equals comment.Post.Id into g select new { post, post.Author,

Entity Framework 4.2 enum support

谁说我不能喝 提交于 2019-12-23 10:06:16
问题 Does EF 4.2 Code First have support for enum types? If so, how do you use it? The following does not create a field for the enum property when using the Nuget EntityFramework package. public class FooContext : DbContext { public IDbSet<Foo> Foos { get; set; } } public class Foo { public int Id { get; set; } public string Name { get; set; } public Category Category { get; set; } } public enum Category {One, Two, Three } var db = new FooContext(); db.Foos.ToList(); 回答1: EF team has changed

Entity Framework - Load only Selected properties

这一生的挚爱 提交于 2019-12-23 09:41:42
问题 I have no hands on experience it EF and hence dont know the relevence of the question. Suppose I have tables named Student (StudentId, Name, Username, Address, DOB, DeptId, NavigationProp1Id.... ) and in Department table (Deptd, DeptName., NavigationProPid). So if a table structure follows like this, when I use 'contex.Studnets ' I can get all prpoerties along with it including navigation properties and if table 2 has other navigation properties it can also be loaded. Am I correct? If so

one-to-one relationships in Entity Framework 4 v2 with POCO

╄→尐↘猪︶ㄣ 提交于 2019-12-23 09:26:31
问题 I've been looking for an example about how to build an one-to-one relationship in EF4v2 with POCO's. I found a lot of examples that show only how to create one-to-many or many-to-many. Do you have any resource about it? 回答1: This worked for me. using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Data; using System.Data.Entity; using System.Data.Entity.ModelConfiguration.Conventions; using System.Linq; class Program { static void Main

Entity framework ObjectContext share - pros and cons

我的未来我决定 提交于 2019-12-23 09:24:57
问题 In my project I use entity framework 4.0 as ORM to persist data in a SQL Server. My project is a ribbon from application with a grid view and navigation tree in the main form with ribbon panel on top of it. My app basically acts a CRUD UI with very little business logic. Being first time with EF, I developed this project by creating and holding an instance of objectContext in the orchestrating form (main form or the one that shows up as application to user) as a member variable and bound a

Entity Framework 4.1 - How to “Force” EF To Go To DB Instead of Using Graph?

混江龙づ霸主 提交于 2019-12-23 09:17:35
问题 Here's the scenario, i have a website, which in a single HTTP request (HTTP POST), i need to do the following: Grab an object (let's say "Tag") Save some other object (let's say "Question") Get a fresh copy of "Tag". Redirect to another page, which needs a fresh copy of "Tag". Behind the scenes, 2) involves database-side triggers that affects data on "Tag". So when i do 3), EF is pulling the same copy of the object from step 1), since it's in the graph/internal memory (e.g same connection

Entity Framework 4.0 Entity SQL passing null ObjectParameter parameters

限于喜欢 提交于 2019-12-23 09:02:02
问题 I have an Entity SQL query: SELECT VALUE t FROM MyEntities AS t WHERE t.Name = @p OR (@p IS NULL AND t.Name IS NULL) I can execute the query as follows: var results = context.CreateQuery<WorkflowInstance>( query, new ObjectParameter("p", name)).ToList(); However, if the 'name' variable is null, then I get the System.ArgumentNullException. So I also tried to use DBNull.Value if the name was null, and I get the following exception: System.ArgumentOutOfRangeException was caught Message=The

How to add SQL user-defined function to entity framework?

淺唱寂寞╮ 提交于 2019-12-23 08:49:28
问题 Can I add a SQL function to my .edmx file like I do in .dbml? If I can, how to do that? If I can not, is there any workaround? I tried to Google but can't find any concrete answer about how to do that. Based on the given answer I have created a Stored procedure and tried to add a 'import function', but it says 'the stored procedure returns no column' . Where am I doing wrong? The function: ALTER FUNCTION [dbo].[fn_locationSearch](@keyword varchar(10)) RETURNS TABLE AS RETURN ( SELECT

How to add SQL user-defined function to entity framework?

走远了吗. 提交于 2019-12-23 08:49:21
问题 Can I add a SQL function to my .edmx file like I do in .dbml? If I can, how to do that? If I can not, is there any workaround? I tried to Google but can't find any concrete answer about how to do that. Based on the given answer I have created a Stored procedure and tried to add a 'import function', but it says 'the stored procedure returns no column' . Where am I doing wrong? The function: ALTER FUNCTION [dbo].[fn_locationSearch](@keyword varchar(10)) RETURNS TABLE AS RETURN ( SELECT