views:

24

answers:

1

For example in my Model.edmx file I have:

        <Schema Namespace="dbModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl"&gt;
  <EntityContainer Name="dbModelStoreContainer">
    <EntitySet Name="Students" EntityType="dbModel.Store.Students" store:Type="Tables" Schema="dbo" />
    <EntitySet Name="Teachers" EntityType="dbModel.Store.Teachers" store:Type="Tables" Schema="dbo" />
  </EntityContainer>
  <EntityType Name="Students">
    <Key>
      <PropertyRef Name="Id" />
    </Key>
    <Property Name="Id" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
    <Property Name="Name" Type="nvarchar(max)" Nullable="false" />
    <Property Name="TeacherId" Type="int" Nullable="false" />
  </EntityType>
  <EntityType Name="Teachers">
    <Key>
      <PropertyRef Name="Id" />
    </Key>
    <Property Name="Id" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
    <Property Name="Name" Type="nvarchar(max)" Nullable="false" />
  </EntityType>
  <Function Name="ListAllStudents" IsComposable="false">
  <CommandText>
    select * from student
    WHERE teacherid = @id;
  </CommandText>
  <Parameter Name="id"
             Mode="In"
             Type="int"/>
</Function>

</Schema>

Is it possible for

<Function Name="ListAllStudents" IsComposable="false">
  <CommandText>
    select * from student
    WHERE teacherid = @id;
  </CommandText>
  <Parameter Name="id"
             Mode="In"
             Type="int"/>
</Function>

to live outside of the Model.edmx and reference it? What I want to do is similar in nature to breaking out the different web.config sections into their own XML file. I don't want to make the EDMX file huge for a project since I will have quite a few defined queries.

**EDIT: Code First is not really a liable options since I will be working with a (legacy) database already defined.

+2  A: 

I don't know of any direct way to do what you're seeking. However, a couple of alternatives that you might consider: first, often there is no reason to put everything inside a single monolithic edmx file. Look for areas where you can use multiple edmx files to "logically group" various aspects of your application. Often this is a good way to break things apart.

Additionally, if you are using the latest version of EF (EF4), have a look at the "code first" approach. This introduces an interesting "separation of concerns" where you have mapping classes dedicated to how your mapping your entities to your model and this are all broken apart into their own classes so you don't end up with a monolithic mapping file. In fact, it's just a collection of C# classes.

Steve Michelotti
+1 for suggesting EF4. Hard to beat the badassry of being able to generate the database on demand.
Nathan Taylor