엔터티 프레임 워크 데이터베이스를 처음 사용할 때 생성자를 보호하려면 어떻게합니까? 내 데이터베이스에서 엔터티 데이터 모델을 생성 할 때 자동 생성 된 클래스는 public 생성자를 포함엔터티 프레임 워크 데이터베이스의 첫 번째 보호 된 생성자
,
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Domain.Models
{
using System;
using System.Collections.Generic;
public partial class MyClass
{
public MyClass()
{
은 제가하고 싶은 것은 당신은 캔트이 보호 된 생성자
public partial class MyClass
{
protected MyClass()
{
초기 반응은 모델을 새로 고침하면 수동으로 변경 사항을 덮어 쓸 수 있기 때문에 데이터베이스에서 처음에는 불가능하다고 생각합니다. – IronMan84
왜 그렇게하고 싶습니까? 이 방법으로이 클래스의 인스턴스를 만드는 것은 불가능합니다. 사용자가 기본 클래스를 인스턴스화하지 못하게하려고합니까? 그런 다음 디자이너에서 기본 클래스를 추상으로 표시 할 수 있는지 확인하십시오. –
@PanagiotisKanavos 내 모델 상태가 유효 함을 보장 할 수 있도록 특정 서명이 필요한 부분 클래스를 만듭니다. 예 : MyClass (person person) {this.Person = person }. 자세한 설명을 보려면 여기를 참고하십시오. http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/ –