2012-11-29 32 views
7

Tôi đang cố gắng thiết lập một dự án thử nghiệm rất đơn giản để đánh giá các khả năng của Mono Entity Framework. Khi cố gắng truy cập dữ liệu, tôi nhận được một ngoại lệ thời gian chạy về phân tích cú pháp dữ liệu mô hình khi sử dụng .NET Runtime. Khi sử dụng thời gian chạy Mono, một ngoại lệ stackoverflow được ném ra.Làm thế nào để thiết lập Entity Framework/SQL Server với Mono

Điều này có vẻ là một lỗi mono nội bộ xảy ra khi biên soạn CSDL Schema phiên bản 3 - xem Mono Bugtracker.

Vì vậy, câu hỏi của tôi là:

Làm thế nào để thiết lập Mono với Entity Framework để làm việc với một Microsoft SQL Server? Vì tôi không tìm thấy nhiều thông tin, nên điều này thậm chí có thể thực hiện được không? Có ai trong số các bạn thành công trong việc thiết lập một giải pháp mono bằng EF và gặp phải các lỗi tương tự không?

Đây là những gì tôi đã làm cho đến nay:

  • cài đặt Mono 3.0.1 Beta (mới nhất ổn định không bao gồm EntityFramework.dll)
  • Thiết lập một Mono Profile cho Visual Studio
  • Disabled strong name verification for delay signed assembilies cho EntityFramework.dll/EntityFramework.SQLServer.dll và thêm chúng vào GAC để ngăn chặn các lỗi thời gian chạy
  • Tạo một mô hình đơn giản + Các mục tạo mã được thêm vào
  • viết code sử dụng mô hình

Mã này hoạt động với Microsoft EntityFramework.dll (Phiên bản 6, Prerelease). Khi sử dụng Mono tương đương, có vẻ như có vấn đề trong khi phân tích các mô hình thực thể:

nhắn ngoại lệ (NET Runtime):

Object tài liệu tham khảo không được đặt để một thể hiện của một đối tượng.

stacktrace (NET Runtime):

at System.Xml.XmlTextReaderImpl.InitStreamInput(Uri baseUri, String baseUriStr, Stream stream, Byte[] bytes, Int32 byteCount, Encoding encoding) 
    at System.Xml.XmlTextReaderImpl..ctor(String url, Stream input, XmlNameTable nt) 
    at System.Xml.XmlTextReader..ctor(Stream input) 
    at System.Data.Entity.Core.EntityModel.SchemaObjectModel.Schema.SomSchemaSetHelper.AddXmlSchemaToSet(XmlSchemaSet schemaSet, XmlSchemaResource schemaResource, HashSet`1 schemasAlreadyAdded) 
    at System.Data.Entity.Core.EntityModel.SchemaObjectModel.Schema.SomSchemaSetHelper.AddXmlSchemaToSet(XmlSchemaSet schemaSet, XmlSchemaResource schemaResource, HashSet`1 schemasAlreadyAdded) 
    at System.Data.Entity.Core.EntityModel.SchemaObjectModel.Schema.SomSchemaSetHelper.ComputeSchemaSet(SchemaDataModelOption dataModel) 
    at System.Data.Entity.Core.Common.Utils.Memoizer`2.Result.GetValue() 
    at System.Data.Entity.Core.Common.Utils.Memoizer`2.Evaluate(TArg arg) 
    at System.Data.Entity.Core.EntityModel.SchemaObjectModel.Schema.SomSchemaSetHelper.GetSchemaSet(SchemaDataModelOption dataModel) 
    at System.Data.Entity.Core.EntityModel.SchemaObjectModel.Schema.Parse(XmlReader sourceReader, String sourceLocation) 
    at System.Data.Entity.Core.EntityModel.SchemaObjectModel.SchemaManager.ParseAndValidate(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModel, AttributeValueNotification providerNotification, AttributeValueNotification providerManifestTokenNotification, ProviderManifestNeeded providerManifestNeeded, IList`1& schemaCollection) 
    at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Loader.LoadItems(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths) 
    at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Init(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths, Boolean throwOnError, DbProviderManifest& providerManifest, DbProviderFactory& providerFactory, String& providerManifestToken, Memoizer`2& cachedCTypeFunction) 
    at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection..ctor(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths) 
    at System.Data.Entity.Core.Metadata.Edm.MetadataCache.StoreMetadataEntry.LoadStoreCollection(EdmItemCollection edmItemCollection, MetadataArtifactLoader loader) 
    at System.Data.Entity.Core.Metadata.Edm.MetadataCache.LoadItemCollection[T](IItemCollectionLoader`1 itemCollectionLoader, T entry) 
    at System.Data.Entity.Core.Metadata.Edm.MetadataCache.GetOrCreateStoreAndMappingItemCollections(String cacheKey, MetadataArtifactLoader loader, EdmItemCollection edmItemCollection, Object& entryToken) 
    at System.Data.Entity.Core.EntityClient.EntityConnection.LoadStoreItemCollections(MetadataWorkspace workspace, DbConnection storeConnection, DbConnectionOptions connectionOptions, EdmItemCollection edmItemCollection, MetadataArtifactLoader artifactLoader) 
    at System.Data.Entity.Core.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections) 
    at System.Data.Entity.Core.EntityClient.EntityConnection.InitializeMetadata(DbConnection newConnection, DbConnection originalConnection, Boolean closeOriginalConnectionOnFailure) 
    at System.Data.Entity.Core.EntityClient.EntityConnection.Open() 
    at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection() 
    at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) 
    at System.Data.Entity.Core.Objects.ObjectQuery`1.<GetEnumerator>m__2C3() 
    at System.Lazy`1.CreateValue() 
    at System.Lazy`1.LazyInitValue() 
    at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext() 
    at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source) 
    at System.Linq.Queryable.Count[TSource](IQueryable`1 source) 
    at EntityFrameworkMono.Program.Main(String[] args) in c:\Users\Christopher Dresel\Documents\Visual Studio 2012\Projects\New\EntityFrameworkMono\EntityFrameworkMono\Program.cs:line 17 
    at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
    at System.Threading.ThreadHelper.ThreadStart() 

nhắn ngoại lệ (Mono Runtime):

Các hoạt động yêu cầu gây ra một chồng tràn.

stacktrace (Mono Runtime):

at System.Xml.Schema.XmlSchemaGroupBase.CheckRecursion (Int32 depth, System.Xml.Schema.ValidationEventHandler h, System.Xml.Schema.XmlSchema schema) [0x00000] in <filename unknown>:0 
    at System.Xml.Schema.XmlSchemaGroupBase.CheckRecursion (Int32 depth, System.Xml.Schema.ValidationEventHandler h, System.Xml.Schema.XmlSchema schema) [0x00000] in <filename unknown>:0 
    at System.Xml.Schema.XmlSchemaElement.CheckRecursion (Int32 depth, System.Xml.Schema.ValidationEventHandler h, System.Xml.Schema.XmlSchema schema) [0x00000] in <filename unknown>:0 
    at System.Xml.Schema.XmlSchemaGroupBase.CheckRecursion (Int32 depth, System.Xml.Schema.ValidationEventHandler h, System.Xml.Schema.XmlSchema schema) [0x00000] in <filename unknown>:0 
    at System.Xml.Schema.XmlSchemaGroupBase.CheckRecursion (Int32 depth, System.Xml.Schema.ValidationEventHandler h, System.Xml.Schema.XmlSchema schema) [0x00000] in <filename unknown>:0 
    at System.Xml.Schema.XmlSchemaElement.CheckRecursion (Int32 depth, System.Xml.Schema.ValidationEventHandler h, System.Xml.Schema.XmlSchema schema) [0x00000] in <filename unknown>:0 
    at System.Xml.Schema.XmlSchemaGroupBase.CheckRecursion (Int32 depth, System.Xml.Schema.ValidationEventHandler h, System.Xml.Schema.XmlSchema schema) [0x00000] in <filename unknown>:0 
    at System.Xml.Schema.XmlSchemaGroupBase.CheckRecursion (Int32 depth, System.Xml.Schema.ValidationEventHandler h, System.Xml.Schema.XmlSchema schema) [0x00000] in <filename unknown>:0 
... 

Đây là mã Tôi đang sử dụng:

CustomerEntities entities = new CustomerEntities(); 
var count = entities.Customers.Count(); // Exception throws here 

Console.WriteLine(count); 
Console.ReadKey(); 

EDMX tập tin

<?xml version="1.0" encoding="utf-8"?> 
<edmx:Edmx Version="3.0" xmlns:edmx="http://schemas.microsoft.com/ado/2009/11/edmx"> 
    <!-- EF Runtime content --> 
    <edmx:Runtime> 
     <!-- SSDL content --> 
     <edmx:StorageModels> 
      <Schema Namespace="CustomerModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl"> 
       <EntityContainer Name="CustomerModelStoreContainer"> 
        <EntitySet Name="Customer" EntityType="CustomerModel.Store.Customer" store:Type="Tables" Schema="dbo" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" /> 
       </EntityContainer> 
       <EntityType Name="Customer"> 
        <Key> 
         <PropertyRef Name="CustomerID" /> 
        </Key> 
        <Property Name="CustomerID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" /> 
        <Property Name="CustomerName" Type="nvarchar" Nullable="false" MaxLength="50" /> 
       </EntityType> 
      </Schema> 
     </edmx:StorageModels> 
     <!-- CSDL content --> 
     <edmx:ConceptualModels> 
      <Schema Namespace="CustomerModel" Alias="Self" annotation:UseStrongSpatialTypes="false" xmlns="http://schemas.microsoft.com/ado/2009/11/edm" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation"> 
       <EntityContainer Name="CustomerEntities" annotation:LazyLoadingEnabled="true"> 
        <EntitySet Name="Customers" EntityType="CustomerModel.Customer" /> 
       </EntityContainer> 
       <EntityType Name="Customer"> 
        <Key> 
         <PropertyRef Name="CustomerID" /> 
        </Key> 
        <Property Name="CustomerID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" /> 
        <Property Name="CustomerName" Type="String" Nullable="false" MaxLength="50" Unicode="true" FixedLength="false" /> 
       </EntityType> 
      </Schema> 
     </edmx:ConceptualModels> 
     <!-- C-S mapping content --> 
     <edmx:Mappings> 
      <Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2009/11/mapping/cs"> 
       <EntityContainerMapping StorageEntityContainer="CustomerModelStoreContainer" CdmEntityContainer="CustomerEntities"> 
        <EntitySetMapping Name="Customers"> 
         <EntityTypeMapping TypeName="CustomerModel.Customer"> 
          <MappingFragment StoreEntitySet="Customer"> 
           <ScalarProperty Name="CustomerID" ColumnName="CustomerID" /> 
           <ScalarProperty Name="CustomerName" ColumnName="CustomerName" /> 
          </MappingFragment> 
         </EntityTypeMapping> 
        </EntitySetMapping> 
       </EntityContainerMapping> 
      </Mapping> 
     </edmx:Mappings> 
    </edmx:Runtime> 
</edmx:Edmx> 

Và cuối cùng là chuỗi kết nối Tôi đang sử dụng:

<connectionStrings> 
    <add name="CustomerEntities" 
     connectionString="metadata=.\CustomerModel.csdl|.\CustomerModel.ssdl|.\CustomerModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=CHRISTOPHERPC\SQLExpress;initial catalog=test;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" 
     providerName="System.Data.EntityClient"/> 
</connectionStrings> 
+0

Bạn đã thử Mono 2.11.3 hoặc mới hơn? –

+0

Tôi đã dùng thử Mono 3.0.1 Beta từ http://www.go-mono.com/mono-downloads/download.html - hiện đã có Phiên bản mới (3.0.2), tôi sẽ thử lại với phiên bản này và đăng kết quả của tôi. – Dresel

+0

Lỗi tương tự khi sử dụng 3.0.2 ... – Dresel

Trả lời

5

Dresel, gây hiểu nhầm vì danh tiếng của tôi có thể ở trên trang này, tôi có thể an toàn nói rằng sử dụng EntityFramework với mono không phải là cách tiếp cận được khuyến nghị tại thời điểm này. Mặc dù về mặt kỹ thuật "được hỗ trợ", phần lớn thư viện không hoạt động tốt nhất. Sau khi chi tiêu khoảng một tháng đào xa như tôi có thể đi, tôi đã không thể để peg khả năng làm cho một trang web đầy đủ chức năng trên% 20. Tôi thay vì sử dụng NHibernate và đã được vui mừng với kết quả. Và khuyên bạn nên làm tương tự cho đến khi cơ sở đã củng cố hơn nữa cho dự án EF Mono. Nhibernate Example (using MySQL, MSSQL supported)

Tôi hy vọng điều này sẽ giúp ít nhất một chút vì đó chỉ là suy nghĩ chân thành của tôi. Chúc may mắn về bất cứ điều gì bạn chọn để làm, tôi biết động thái MS Opensource này có thể nhận được rất "rào cản"

+0

chỉ tò mò - khi bạn nói "thư viện không chức năng", bạn đang nói về các phiên bản mono mới nhất (3.x)? –

+0

Đối với nhóm của tôi và bản thân tôi đang chạy Ubuntu và tất cả phần mềm mới nhất vào cuối tháng 12. Chúng là các thư viện biên dịch trong các cửa sổ, nhưng một số thứ cần thiết không được hỗ trợ tại thời điểm đó. – Chazt3n

+0

ok, cảm ơn nhiều. –

Các vấn đề liên quan