>>>>>>Hi,
>>>>>>
>>>>>>I am watching one of the Pluralsight courses on EF (by Julie Lerman). The first thing she creates is a class project with a file .classes where she writes 3 classes (Ninja, Clan, NinjaEquipment).
>>>>>>
>>>>>>Does it mean that when I prepare
my application database to be used with EF I have to create a similar class library classes.cs with a class for each of the tables in my database?
>>>>>
>>>>>That is the code first approach, which I think is stupid - database first is my motto. Look for generators to create such classes from your DB.
>>>>
>>>>I believe that EF 7 done away with the model database first and left only code first model. I understand your suggestion of not wasting time of writing a bunch of code but rather have a tool to do it for you. I will look for the 3P tool to generate such code. But my question was more academic, is such a classes.cs with all classes "matching" my tables required for EF?
>>>>Thank you.
>>>
>>> I suggest you to look at Reverse POCO generator by Simon Hudges
https://efreversepoco.codeplex.com/ We're using it in our current project. Every time you make changes in your database, you simply run the tool to re-generate the classes. In our application we have 2 projects. One is the Data project that contains configurations for each table/view, the other is Models which contains a single class file for each table/view. That project is quite flexible and allows you to generate all you need.
>>
>>Thank for your suggestion for POCO generator.
>>
>>Do I understand correctly that your Models (containing a single class file for each table/view) is what they refer to a Code First? That is, the domain class listing all columns of a table?
>
>Yes, exactly. I'll show you one of the generated classes:
>
>
>// ReSharper disable RedundantUsingDirective
>// ReSharper disable DoNotCallOverridableMethodsInConstructor
>// ReSharper disable InconsistentNaming
>// ReSharper disable PartialTypeWithSinglePart
>// ReSharper disable PartialMethodWithSinglePart
>// ReSharper disable RedundantNameQualifier
>// TargetFrameworkVersion = 4.51
>#pragma warning disable 1591 // Ignore "Missing XML Comment" warning
>
>using System;
>using System.CodeDom.Compiler;
>using System.Collections.Generic;
>using System.ComponentModel.DataAnnotations.Schema;
>using System.Data.Entity;
>using System.Threading;
>
>namespace Siriusware.Models
>{
> // act_actv
> public partial class ActActv
> {
> public decimal ActivId { get; set; } // activ_id (Primary key). Primary key
> public string Account { get; set; } // account
> public decimal InvoiceNo { get; set; } // invoice_no. Invoice number (if applicable)
> public int ActivType { get; set; } // activ_type. Activity type: 10=Print statement
> public string Details { get; set; } // details. Details (if applicable)
> public DateTime DateTime { get; set; } // date_time
> public string Person { get; set; } // person
> public string Location { get; set; } // location
>
> // Foreign keys
> public virtual Accounts Accounts { get; set; } // FK_act_actv_accounts
>
> public ActActv()
> {
> InvoiceNo = 0m;
> Details = "";
> DateTime = System.DateTime.Now;
> Person = "";
> Location = "";
> InitializePartial();
> }
>
> partial void InitializePartial();
> }
>
>}
>
>
>That code is all generated. We do not touch it.
Thank you for sharing the code.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham