code-first

Entity Framework and string as NCLOB on oracle Db

倖福魔咒の 提交于 2020-01-14 10:03:15
问题 I have this model: public class Teacher { public int TeacherID { get; set; } public string Name { get; set: } public string Surname{ get; set; } } and when Model First run, it creates my Teachers table and DbSet, but for Name and Surname (which are string) it assigns NCLOB type to the column. Now, with NCLOB type I cannot do some operations like equals or distincts on my table.... How can I force MF to set columntype to varchar? 回答1: I've managed to solve the issue setting the maximum string

Entity Framework 4 - TPT Inheritance in Features CTP5 (code first): rename foreign key column on inherited table

一曲冷凌霜 提交于 2020-01-14 03:38:07
问题 I'm trying to convert an xml Entity Framework model to Code First (CTP5) one. I have to model a hierarchy which fits quite well the TPT pattern. The only problem I have is that the primary key/foreign key of the "inheriting" table has a different name from the primary key of the base class. These are the relevant fields of the involved tables CREATE TABLE site.Domains ( ID INT NOT NULL PRIMARY KEY, Domain NVARCHAR(128) NOT NULL ) CREATE TABLE site.MainSites ( FKDomainID INT NOT NULL PRIMARY

Table Mapping problem

时光总嘲笑我的痴心妄想 提交于 2020-01-13 06:59:07
问题 I am using entity framework 4 in my current project, to read data from several table. Compare using ADO.net, it EF is very easy, with simple code that can do lots of work or me. But there is one problem... e,g there is and exiting table call Table "MTable" i only want to query two column from this table, however this table is share with other two ppl who are also working on it. they might add column or modify constrains on this table. Only one thing i am sure is that, the two column i want to

Code First vs. Database First

一个人想着一个人 提交于 2020-01-10 09:38:11
问题 I created an Entity Framework model based on an existing database, then generated the POCO entities from the model. The connection string in my web.config isn't Entity Framework, it's just the standard connection string (it's missing the CSDL, SSDL, MSL references). I can compile my application, but when I run I get this error: Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database

How to make persisted computed column in EF code first?

瘦欲@ 提交于 2020-01-10 02:52:08
问题 How do I get this column as similar to a PERSISTED COMPUTED column in the database? My current attempt (it loads all CompCol rows with null in seed) : public class Call { public Call() { } [Key] public int Id { get; set; } [DatabaseGenerated(DatabaseGeneratedOption.Computed)] public string CompCol { get { return "ABC-" + Convert.ToString(Id).PadLeft(5, '0'); } protected set {} } } 回答1: The solution I found was to : Make sure auto migrations are turned off. This is so that VS will generate a

How to remove child one to many related records in EF code first database?

大憨熊 提交于 2020-01-09 04:14:06
问题 Well, I have one-to-many related model: public class Parent { public int Id { get; set; } public string Name { get; set; } public ICollection<Child> Children { get; set; } } public class Child { public int Id { get; set; } public string ChildName { get; set; } } What I want to do is clear Parent.Children and remove related child entities from database. I've already tried: Database context class: modelBuilder.Entity<Parent>() .HasMany(p => p.Children) .WithOptional() .WillCascadeOnDelete(true)

Entity Framework Database.SetInitializer simply not working

帅比萌擦擦* 提交于 2020-01-09 03:33:04
问题 I am having this kind of "mysterious" issue here. I am currently using Entity Framework 4.1 Code First approach with my ASP.NET MVC 3 application, it worked great, until yesterday... Something really bad happened that caused my Database.SetInitializer to stop working. Explained: I have this simple model public class User { public int Id { get; set; } public int RoleId { get; set; } [Required] [StringLength(50)] [DataType(DataType.Text)] public string Login { get; set; } [Required]

MVC EF code first creating model class

ⅰ亾dé卋堺 提交于 2020-01-07 06:36:31
问题 I'm new to MVC and EF code first. I'm in struggle to model a real-estate company DB model using EF code-first approach and I did some exercises as well as reading some online tutorials. First thing I have a customers table that would be in relation with one or more properties he/she has registered as it's owner to sell or to rent, I was wondering if it is possible to have some sub classes inside a model class for registered properties as below: public Property { public int PropertyID { get;

About c# partial class accesibility

丶灬走出姿态 提交于 2020-01-05 13:53:26
问题 I have a question about partial classes in c# In This picture, I have a domain model. I am have added reference this(DomainModelLib) to Client application and repoistory application. Repository application is using this domain model classes as "DbSet" and getting data from database. Realtions are created in model partial classes as you can see. I referenced Model to Client application. I wanna first partial(first red frame) of Product class can access in Client application but second part

About c# partial class accesibility

僤鯓⒐⒋嵵緔 提交于 2020-01-05 13:53:25
问题 I have a question about partial classes in c# In This picture, I have a domain model. I am have added reference this(DomainModelLib) to Client application and repoistory application. Repository application is using this domain model classes as "DbSet" and getting data from database. Realtions are created in model partial classes as you can see. I referenced Model to Client application. I wanna first partial(first red frame) of Product class can access in Client application but second part