code-first

ntext in ServiceStack.OrmLite

强颜欢笑 提交于 2019-12-08 19:21:10
问题 how can i have nText datatype in ServiceStack.OrmLite Code first ? public class Email { [AutoIncrement] public long ID { get; set; } public DateTime Date { get; set; } public string From { get; set; } public string Subject { get; set; } nText => public string Body { get; set; } } if i use string datatype , ormlite generate nVarchar(8000) in database i need more than 8000 character for data 回答1: You need to convert your Body type to byte[] from string for ServiceStack.OrmLite to use the

Is it possible to use LinqPad with a code-first model

ⅰ亾dé卋堺 提交于 2019-12-08 16:01:04
问题 In the past It's been easy to set a connection in LinqPad to a custom assembly that had EF model. Linqpad looks for a that is based on System.Data.Objects.ObjectContext which doesn't exist How (if at all) does one make their model assembly compatible with LinqPad.? 回答1: Right now, LINQPad does not support the EF CTP's code-first: there's a feature request here. It's almost certain that support will be added in the future - if this EF feature makes it past CTP (and maybe sooner with sufficient

GenericRepository TEntity change attribute value

倾然丶 夕夏残阳落幕 提交于 2019-12-08 13:20:57
问题 I am using EF 5.0 and the model first approach. I have build a GenericRepository that has the basic get, insert, delete etc statements. Like: public virtual void Insert(TEntity entity) { dbSet.Add(entity); } My EF entities all have the attributes Modified and ModifiedBy. Now I want to change this values everytime I save an entity. Is it possible to modify this two attributes (set the value) without writing an specific implementation all the time? Thank you 回答1: I see two options for you to do

EF Code first - Detect one-to-many relationships property for given type

泄露秘密 提交于 2019-12-08 13:13:36
问题 We know that we do not need to configure for one-to-many relationships using Data Annotations, one-to-many relationship configured by convention. In following example ICollection<Student> Students is an relationship property public class Student { public Student() { } public int StudentId { get; set; } public string StudentName { get; set; } public virtual Standard Standard { get; set; } } public class Standard { public Standard() { Students = new List<Student>(); } public int StandardId {

Updating DbSet<T> item's value from the controller - C#, MVC, Code First

倾然丶 夕夏残阳落幕 提交于 2019-12-08 12:14:26
here's my question: I have an MVC3 C# application and I need to update a value in a DbSet from the Edit controller, so the T item's value will be replaced with a new one. I don't want to delete the item and add it again. I cannot figure out how to do this. DbSet doesn't seem to have something like an index. Here's my Edit controller: public class ItemController : Controller { private SESOContext db = new SESOContext(); private FindQrs fqr = new FindQrs(); [HttpPost] public ActionResult Edit(Item item) { if (ModelState.IsValid) { db.Entry(item).State = EntityState.Modified; Qr qr = fqr.FindQr

Help implementing simple / custom MembershipProvider

谁都会走 提交于 2019-12-08 10:11:50
问题 I have been follow Steve Sandersons MVC2 book and have implemented a simple / custom MembershipProvider. You will not that a valid user has been hardcoded. My question is how do I get this to validate against my "Profiles" SQLServer table? PS - I am using EF 4.1 Code First Please see below: public class Profile { [Key] public int UserId { get; set; } [Required] public string UserName { get; set; } [Required] public string Password { get; set; } } public class SimpleMembershipProvider :

EF6 CodeFirst One to Many MySQL a foreign key constraint fails

岁酱吖の 提交于 2019-12-08 09:06:25
问题 I'm doing a Mapping from existing Database to CodeFirst and I'm having a problem with One To Many Relationships. System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.Entity. Core.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> MySql.Data.MySqlClient.MySqlException: Cannot add or update a child row: a foreign key constraint fails I have a

define scalar function with ef4.1 code first?

血红的双手。 提交于 2019-12-08 07:12:45
问题 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 ? 回答1: 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

Mapping with entity framework “code first”

给你一囗甜甜゛ 提交于 2019-12-08 04:52:59
问题 I'm trying to map my entities using Entity Framework "code first", but I have a problem with mapping a complex type. Here my simplified exampled: Domain object looks like: public class Customer { public Address DeliveryAddress {get; set;} } public class Address { public string StreetName {get; set;} public string StreetNumber {get; set;} public City City {get; set;} } public class City { public int Id {get; set;} public string Name {get; set;} } and the mapping: public class

EF5 And cycles or multiple cascade paths, FOREIGN KEY

落爺英雄遲暮 提交于 2019-12-08 02:58:20
问题 I got a wierd problem, i already know about why normaly this exception happen and how to solve it by Disablaing WillCascadeOnDelete to False in one of the properties. But my problem seems to be other kind, Here is my code : Memeber : public class Memeber { public int MemberID { get; set; } public virtual ICollection<Message> SentMessages { get; set; } public virtual ICollection<Message> RecievedMessages { get; set; } } public class Message { public long MessageID { get; set; } public int