entity-framework-4

The property 'text' is part of the object's key information and cannot be modified

拜拜、爱过 提交于 2019-12-09 03:02:17
问题 So I have a table in the database, with a column that is simply an nvarchar(800). When I try to do: try { UserTable = (from x in entities.userTable where x.uID == uID select x).Single(); UserTable.DateCreated = DateTime.Now; UserTable.text= newText; Update(UserTable); } I get the exception in catch: "The property 'text' is part of the object's key information and cannot be modified." When I look into the table, I don't see anything under "key" or "index". So it's not a key, I don't understand

EF4 Strip table prefixes on import

穿精又带淫゛_ 提交于 2019-12-09 01:41:50
问题 I am attempting to have table names automatically renamed to strip off a leading prefix in EF4. I know it can be done in the GUI, however, my company created the DB schema in Visio and use that to create the DB creation script in SQL. We do this often, and sometimes have a lot of tables, so using the GUI is not an ideal solution. Is there a way to modify the properties on the .edmx file to strip off a defined prefix from the DB table so the Entity class is how we desire it? 回答1: The simplest

Using SQL Table valued parameter with Entity Framework

谁说胖子不能爱 提交于 2019-12-09 01:24:57
问题 I am using Entity Framework v4.0 in my project to connect to a database. I am in a situation to pass a List as input parameter to a stored procedure and do some manipulations in SP and get back List as SP result. I know table valued parameter is one option. But after some investigation I found it is not possible to use Table Valued parameter in Entity Framework. Is there any other way without using Table Valued Parameter to do it through Entity framework? 回答1: You can still pass a TVP to a

Entity Framework Code First 4.3 / LINQKit predicate for related table

不羁的心 提交于 2019-12-09 00:06:33
问题 I am using Entity Framework 4.3.1 with a Code First approach. Also, I am using LinqKit so as to use the PredicateBuilder. If I have tables like so: Location, TimeZone (Many:1) ..and I wish to have something like so: Expression<Func<TimeZone, bool>> pred = PredicateBuilder.True<TimeZone>(); pred = pred.And(tz => tz.TimeZoneCode == "EST"); List<Location> locations = context.Locations .AsExpandable().Where(pred) .Select(loc => loc).ToList(); This does not work, because the predicate is built to

Why does Setting EntityState to Detached Empty a Property of type List<T>?

天涯浪子 提交于 2019-12-08 23:48:28
问题 Using Entity Framework Code First, I have something like: public class Foo { public int Id { get; set; } public List<Bar> Bars { get; set; } } Foo foo = (from f in ctx.Foos.Include("Bars") where f.Id == 42 select f).Single(); // At this point foo.Bars is populated ctx.Entry(foo).State = EntityState.Detached; // At this point foo.Bars is an empty List Why does detaching an object cause it's property public List<string> Bars , which was explicitly and successfully included, to be emptied? What

Entity Framework 4 - ApplyCurrentValues<TEntity> vs. ObjectStateManager.ChangeObjectState

折月煮酒 提交于 2019-12-08 23:32:38
问题 We have an WCF service with an update method that updates a Customer in the DB. This method get a detached entity from the client. void UpdtaeCustomer(Customer detachedCustomer); We came up with two ways to write this method : 1) context.CustomerSet.Attach(detachedCustomer); context.ObjectStateManager.ChangeObjectState(detachedCustomer, entityState.Modified); context.SaveChanges(); 2) Customer customer = context.GetObjectByKey(detachedCustomer.EntityKey); context.ApplyCurrentValues<Customer>(

Save Entity Framework Linq Query to database

ぐ巨炮叔叔 提交于 2019-12-08 22:22:18
问题 I was wondering if we can convert a Linq Query on the Entity Framework and save the query to the database by converting it to an Expression Tree and Serializing. Can someone please help me on this and point me in a right direction whether this can be done or not. Any help is greatly appreciated on this. Thanks, Ajay. 回答1: i released a library for that purpose just yesterday. Serialize.Linq. It serializes linq expressions to xml, json or binary. using System.Linq.Expressions using Serialize

Generate identity for an Oracle database through Entity Framework using an exisiting stored procedure

China☆狼群 提交于 2019-12-08 21:38:44
问题 How to automatically generate identity for an Oracle database through Entity Framework? I have a function that I could call and generate the column which is not in the context how do I explicitly call the stored procedure through Entity Framework? I am using a repository pattern. Random Number generator to insert a record (where I get the primary key through a UDF and pass this to the entity to insert). 回答1: 1) Create sequence in Oracle CREATE SEQUENCE dummy_test_seq MINVALUE 1 MAXVALUE

Domain Modeling Question using C# with Entity Framework CTP 4

和自甴很熟 提交于 2019-12-08 21:31:38
问题 I am trying to model out a album that has a collection of photos. Each Album will have a collection of Photos and a Photo that is a thumb. This is what I have but EF does not seem to like it: public class Album : IEntity { private DateTime _dateCreated; public Album() { _dateCreated = SystemTime.Now(); Photos = new List<Photo>(); } public long Id { get; set; } public string Name { get; set; } public string Location { get; set; } public DateTime DateCreated { get { return _dateCreated; } set {

define scalar function with ef4.1 code first?

醉酒当歌 提交于 2019-12-08 20:06:29
i have a function called distancebetween i wnat to define it in scalar valued function to call it by linq if there is away to do that by EF4.1 code first ? No. Code first was designed as "code first" = you will create a code and it will create a database where no database logic exists (no views, stored procedures, triggers or functions). Because of that it is completely missing features for mapping database logic like functions and stored procedures. If you want to use it in LINQ you must abandon code-first / fluent-API and start tu use EDMX where this is supported. Using ExecuteSqlCommand and