entity-framework-4

Is there a practical way to use the hierarchyID datatype in entity framework 4?

萝らか妹 提交于 2019-12-18 03:14:09
问题 As it stands now, the CLR UDTs including HierarchyID aren't supported in Entity Framework 4. HierarchyID.ToString() is useful, but breaks down once any item has 10+ siblings (the basic structure is /3/4/12/ or /3/4/2/ so the 12th node will sort before the 2nd node). A little more about potential options: Bring back hierarchyID as a varbinary and implement my own binary sorter Bring back hierarchyID as a varbinary and implement my own hierarchyID.ToString() method which pads the numbers with

Entity Framework 4 CTP 5 Self Referencing Many-to-Many

爷,独闯天下 提交于 2019-12-18 02:49:38
问题 I have the following scenario in my database. It is a record of Studies and those studies have other studies as prerequisites. In my DB design, it looks like this: And my code looks something like this: public class Study { public int ID { get; set; } public string Topic { get; set; } public byte TypeID { get; set; } public virtual StudyType Type { get; set; } public bool Deprecated { get; set; } public virtual ICollection<Study> Prerequisites { get; set; } } public class StudyType { public

EF4 - update [Table] set @p = 0 where

那年仲夏 提交于 2019-12-18 01:15:19
问题 While going through SQL profiler, I noticed the following query generated by EF4. exec sp_executesql N'declare @p int update [dbo].[User] set @p = 0 where (([UserID] = @0) and ([RowVersion] = @1)) select [RowVersion] from [dbo].[User] where @@ROWCOUNT > 0 and [UserID] = @0',N'@0 int,@1 binary(8)',@0=1,@1=0x000000000042DDCD I am not sure why EF4 generates this while I am actually not updating any columns of the User table in that UnitOfWork. Running this query updates the RowVersion column

How to return values from a dynamic SQL Stored Procedure to the Entity Framework?

时间秒杀一切 提交于 2019-12-18 01:13:36
问题 I have a Stored Procedure which executes some dynamic SQL. I want to use this Stored Procedure in entity framework 4, but when I try to create a complex type the procedure returns no columns. Is there any way I can force it to return my values and get the entity framework to receive them? Here is a much-simplified example of what I want to do: CREATE PROCEDURE sp_calculatesalary(@EmployeeId as int) begin declare dynsql as varachar(500) @dynsql='Select @Salary=Salary,@UserName=Username from

EntityFunctions.TruncateTime and unit tests

会有一股神秘感。 提交于 2019-12-17 22:57:18
问题 I'm using System.Data.Objects.EntityFunctions.TruncateTime method to get date part of a datetime in my query: if (searchOptions.Date.HasValue) query = query.Where(c => EntityFunctions.TruncateTime(c.Date) == searchOptions.Date); This method (I believe the same applies to other EntityFunctions methods) cannot be executed outside of LINQ to Entities. Executing this code in a unit test, which effectively is LINQ to objects, causes a NotSupportedException to be thrown: System

How to do Migration when Generate database from model in Entity Framework Model First

柔情痞子 提交于 2019-12-17 22:23:59
问题 I have an existing model and initially generated the database from this model and had populated the existing tables with some data. Now I've added a new table to the model. Is there a way to update the database from the new model without losing all the data in the existing tables? Thanks. 回答1: EF's default database generation workflow creates a full script that will recreate your database every time you select Generate Database from Model... so if you execute it in your DB you will lose all

EF 4.0 model caching the data, and does not detect the modified data

被刻印的时光 ゝ 提交于 2019-12-17 20:34:46
问题 I am developing ASP.NET application and I have problem with the EF 4.0 model. The EF model detects the newly added and deleted data, but not the modified data from the database. Here is an example of the problem what I have. A- Database: Script to generate the "Employees" database table CREATE TABLE [dbo].[Employees] ( [id] [int] IDENTITY(1, 1) NOT NULL, [name] [nvarchar](50) NULL, CONSTRAINT [PK_Employees] PRIMARY KEY CLUSTERED ( [id] ASC ) WITH ( PAD_INDEX = OFF, STATISTICS_NORECOMPUTE =

Entity Framework Code First - Change Table Column Collation

Deadly 提交于 2019-12-17 20:17:00
问题 I'm using Entity Framework CTP5 and Code First. I need to change the Collation for a specific column in SQL Server. I believe the default collation is SQL_Latin1_General_CP1_CI_AS, but I need to change this one column colllation to SQL_Latin1_General_CP1_CS_AS (Case Sensitive). Is there a way to use ModelBuilder in Code First to change a specific column collation? BarDev 回答1: Model builder doesn't allow this but you can create custom database initializer and execute ALTER TABLE command. The

LINQ Dynamic Query Library

廉价感情. 提交于 2019-12-17 19:28:20
问题 I am building an ASP.Net MVC 3 application with Entity Framework 4. When the two pieces of code below are executed, both variables (query1 and query2) have a return type of System.Data.Objects.ObjectQuery<Asset.Model.Equipment> Query1 uses a direct instance of the ObjectContext, however, Query2 uses a repository pattern, ie, it calls GetEquipment in EquipmentService, which in turns calls the same named method in Equipment Repository. Both the methods in the Service and Repository return

How to limit number of related data with Include

对着背影说爱祢 提交于 2019-12-17 19:23:13
问题 class Cat { public int CatID; public string Name; public ICollection<Post> Posts; } class Post { public int PostID; public string Name public int CatID; public virtual Cat Parent; } And I want to load all the Catergories with their Posts so: var cats = context.Cat.Include(c => c.Posts); Now I want to limit the number of Posts that are returned, can someone show mw how to do that? I'm using EntityFramework 4.3.1 回答1: It is not possible with eager loading ( Include ) - eager loading returns